- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Density Plots with Pandas for a specific attribute
We will use plot.density() to density plot on a Dataset in the form of a csv file. Let’s say the following is our dataset − Cricketers2.csv
At first, import the required libraries −
import pandas as pd import matplotlib.pyplot as plt
Load data from a CSV file into a Pandas DataFrame −
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers2.csv")
Plotting the density plot. Attribute considered is "Age" −
dataFrame.Age.plot.density(color='green')
Example
Following is the complete code −
import pandas as pd import matplotlib.pyplot as plt # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers2.csv") # plotting the density plot # attribute considered is "Age" dataFrame.Age.plot.density(color='green') plt.title('Density plot = Age') plt.show()
Output
This will produce the following output −
- Related Articles
- Python - Search DataFrame for a specific value with pandas
- Compare specific Timestamps for a Pandas DataFrame – Python
- Python Pandas - Draw a set of horizontal bar plots with Seaborn
- Python Pandas - Draw a set of Horizontal point plots with Seaborn
- Annotate bars with values on Pandas bar plots in Python
- Python Pandas - Mask and replace NaNs with a specific value
- Python Pandas - Draw a set of vertical bar plots grouped by a categorical variable with Seaborn
- Python Pandas - Draw a set of vertical point plots grouped by a categorical variable with Seaborn
- Why doesn’t Python have a “with” statement for attribute assignments?
- Python Pandas - Draw vertical bar plots with nested grouping by two categorical variables in Seaborn
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Python - Sum only specific rows of a Pandas Dataframe
- Making matplotlib scatter plots from dataframes in Python's pandas
- Python Pandas - Extract the minute from DateTimeIndex with specific time series frequency
- Python Pandas - Extract year from the DateTimeIndex with specific time series frequency

Advertisements