Difference between pd.df.plot.box() and pd.df.boxplot()
Asked Answered
P

2

6

Why pandas has two funcitons for Boxplot : pandas.DataFrame.plot.box() and pandas.DataFrame.boxplot() ?

df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
df.plot.box()

enter image description here

df.boxplot()

enter image description here

Plumbism answered 28/12, 2018 at 22:40 Comment(1)
The answer will probably be along the lines of "API bloat" more than anything more insightful. Pandas is deprecating things all over the place.Herzel
G
3

Both return a 'matplotlib.axes._subplots.AxesSubplot' object. Obviously, they are calling upon different parts of the pandas library to execute.

One of the consequences of this is that the pandas.DataFrame.plot.box() method uses the FramePlotMethods class where "grid = None" and pandas.DataFrame.boxplot() has "grid = True" by default. You'll notice this in the background lines in your two charts.

Additionally, .boxplot() can't be used on a Series, whereas .plot's can.

Goddamned answered 28/12, 2018 at 23:39 Comment(0)
A
0

df.plot.box does not accept the column keyword argument

to_plot = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])

# This line will error:
# to_plot.plot.box(column='B')

# This line will not error, will work:
to_plot.boxplot(column='B')
Ace answered 1/8, 2019 at 5:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.