Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

density plot

What is a density plot in Pandas?

Educative Answers Team

Pandas is a popular Python-based data analysis toolkit that can be imported using:

import pandas as pd

It presents a diverse range of utilities, from parsing multiple file-formats to converting an entire data table into a NumPy matrix array. This property makes Pandas a trusted ally in data science and machine learning.

Pandas can help with the creation of multiple types of data analysis graphs. One such example is the density plota density plot is made by generating KDE

Density plots plot a continuous graph and can help to observe the distribution of a variable in a dataset. Like histograms, density plots use bins, but then smooth out the edges to reduce noise.

The default implementation of a density plot is:

DataFrame.plot.kde( bw_method = None, ind = None, **kwargs)


  • bw_method: str, callable, scalar - This is used to calculate the estimator bandwidth. It can be ‘scott’, ‘silverman,’ a scalar constant, or a callable.

  • y: int or NumPy array - Evaluation points for the estimated KDE. If int, the points are equally spaced. If NumPy array, they are evaluated at the points passed. It defaults to 1000 equally spaced points.

  • **kwargs: tuple (rows, columns) - All other plotting keyword arguments to be passed to pandas.%(this-datatype)s.plot().


The following code shows how a density plot can be added to Python. You can change different parameters and look at how the output varies.
#import library
import pandas as pd

#add csv file to dataframe
series = pd.Series([0, 1, 2, 2.5, 3, 4, 5])

#create density plot
densityplot = series.plot.kde()


density plot
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring