

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 - How to plot a Pandas DataFrame in a Bar Graph
Let’s say the following are the contents of our CSV file −
Car Reg_Price 0 BMW 2000 1 Lexus 1500 2 Audi 1500 3 Jaguar 2000 4 Mustang 1500
Import the required libraries −
import pandas as pd import matplotlib.pyplot as mp
Our CSV file is on the Desktop. Load data from a CSV file into a Pandas DataFrame −
d = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesData.csv") dataFrame = pd.DataFrame(d.head(), columns=["Car","Reg_Price"])
Plot the DataFrame −
dataFrame.plot(x="Car", y="Reg_Price", kind="bar", figsize=(10, 9))
Example
Following is the code −
import pandas as pd import matplotlib.pyplot as mp # read csv d = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesData.csv") print("\nReading the CSV file...\n",d) # dataframe dataFrame = pd.DataFrame(d.head(), columns=["Car","Reg_Price"]) # plotting the dataframe dataFrame.plot(x="Car", y="Reg_Price", kind="bar", figsize=(10, 9)) # displaying bar graph mp.show()
Output
This will display the following output −
- Related Questions & Answers
- Python - Plot a Pandas DataFrame in a Line Graph
- How to plot a bar graph in Matplotlib from a Pandas series?
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- How to plot a Pandas Dataframe with Matplotlib?
- Python Pandas - Plot a Stacked Horizontal Bar Chart
- Python - Draw a Scatter Plot for a Pandas DataFrame
- Python Pandas - Plot multiple data columns in a DataFrame?
- How to plot a graph in Python?
- How to plot an area in a Pandas dataframe in Matplotlib Python?
- How to give a Pandas/Matplotlib bar graph custom colors?
- Create a Bar plot with SeaBorn – Python Pandas
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Python - Plot a Pie Chart for Pandas Dataframe with Matplotlib?
- How to export to PDF a graph based on a Pandas dataframe in Matplotlib?
- Plot multiple columns of Pandas dataframe on the bar chart in Matplotlib
Advertisements