Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.plot.box#

DataFrame.plot.box(by=None,**kwargs)[source]#

Make a box plot of the DataFrame columns.

A box plot is a method for graphically depicting groups of numericaldata through their quartiles.The box extends from the Q1 to Q3 quartile values of the data,with a line at the median (Q2). The whiskers extend from the edgesof box to show the range of the data. The position of the whiskersis set by default to 1.5*IQR (IQR = Q3 - Q1) from the edges of thebox. Outlier points are those past the end of the whiskers.

For further details see Wikipedia’sentry forboxplot.

A consideration when using this chart is that the box and the whiskerscan overlap, which is very common when plotting small sets of data.

Parameters:
bystr or sequence

Column in the DataFrame to group by.

Changed in version 1.4.0:Previously,by is silently ignore and makes no groupings

**kwargs

Additional keywords are documented inDataFrame.plot().

Returns:
matplotlib.axes.Axes or numpy.ndarray of them

See also

DataFrame.boxplot

Another method to draw a box plot.

Series.plot.box

Draw a box plot from a Series object.

matplotlib.pyplot.boxplot

Draw a box plot in matplotlib.

Examples

Draw a box plot from a DataFrame with four columns of randomlygenerated data.

>>>data=np.random.randn(25,4)>>>df=pd.DataFrame(data,columns=list('ABCD'))>>>ax=df.plot.box()
../../_images/pandas-DataFrame-plot-box-1.png

You can also generate groupings if you specify theby parameter (whichcan take a column name, or a list or tuple of column names):

Changed in version 1.4.0.

>>>age_list=[8,10,12,14,72,74,76,78,20,25,30,35,60,85]>>>df=pd.DataFrame({"gender":list("MMMMMMMMFFFFFF"),"age":age_list})>>>ax=df.plot.box(column="age",by="gender",figsize=(10,8))
../../_images/pandas-DataFrame-plot-box-2.png

[8]ページ先頭

©2009-2025 Movatter.jp