w3resource

Pandas DataFrame: boxplot() function

DataFrame.boxplot() function

The boxplot() function is used to make a box plot from DataFrame columns.

Make a box-and-whisker plot from DataFrame columns, optionally grouped by some other columns. A box plot is a method for graphically depicting groups of numerical data 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 edges of box to show the range of the data. The position of the whiskers is set by default to 1.5 * IQR (IQR = Q3 - Q1) from the edges of the box. Outlier points are those past the end of the whiskers.

Syntax:

DataFrame.boxplot(self, column=None, by=None, ax=None, fontsize=None, rot=0, grid=True, figsize=None, layout=None, return_type=None, **kwds)

Parameters:

Name Description Type/Default Value Required / Optional
column             Column name or list of names, or vector. Can be any valid input to str or list of str Optional
by  Column in the DataFrame to pandas.DataFrame.groupby(). One box-plot will be done per value of columns in by. str or array-like Optional
ax The matplotlib axes to be used by boxplot. object of class matplotlib.axes.Axes Optional
fontsize Tick label font size in points or as a string (e.g., large). float or str Required
rot The rotation angle of labels (in degrees) with respect to the screen coordinate system. int or float
Default Value: 0
Required
grid Setting this to True will show the grid. bool
Default Value: True
Required
figsize The size of the figure to create in matplotlib. A tuple (width, height) in inches Required
layout For example, (3, 5) will display the subplots using 3 columns and 5 rows, starting from the top-left. tuple (rows, columns) Optional
return_type The kind of object to return. The default is axes.
  • 'axes' returns the matplotlib axes the boxplot is drawn on.
  • 'dict' returns a dictionary whose values are the matplotlib Lines of the boxplot.
  • 'both' returns a namedtuple with the axes and dict.
  • when grouping with by, a Series mapping columns to return_type is returned.
    If return_type is None, a NumPy array of axes with the same shape as layout is returned.
{'axes', 'dict', 'both'} or None
Default Value: 'axes'
Required
**kwds All other plotting keyword arguments to be passed to matplotlib.pyplot.boxplot().   Required

Returns: result.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame.plot.scatter() function
Next: DataFrame.hist() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/pandas/dataframe/dataframe-boxplot.php