
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- 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 an area in a Pandas dataframe in Matplotlib Python?
- How to plot a Pandas Dataframe with Matplotlib?
- Python - Draw a Scatter Plot for a Pandas DataFrame
- Python Pandas - Plot multiple data columns in a DataFrame?
- Python Pandas - Plot a Stacked Horizontal Bar Chart
- Create a Bar plot with SeaBorn – Python Pandas
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- How to plot a graph in Python?
- How to give a Pandas/Matplotlib bar graph custom colors?
- Plot multiple columns of Pandas dataframe on the bar chart in 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?

Advertisements