
- 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 - Plot a Pandas DataFrame in a Line Graph
To plot a DataFrame in a Line Graph, use the plot() method and set the kind parameter to line. Let us first import the required libraries −
import pandas as pd import matplotlib.pyplot as mp
Following is our data with Team Records −
data = [["Australia", 2500, 2021],["Bangladesh", 1000, 2021],["England", 2000, 2021],["India", 3000, 2021],["Srilanka", 1500, 2021]]
Set the data as Pandas DataFrame and add columns −
dataFrame = pd.DataFrame(data, columns=["Team","Rank_Points", "Year"])
Plot the Pandas DataFrame in a line graph. We have set the “kind” parameter as “line” for this −
dataFrame.plot(x="Team", y=["Rank_Points","Year" ], kind="line", figsize=(10, 9))
Example
Following is the code −
import pandas as pd import matplotlib.pyplot as mp # our data data = [["Australia", 2500, 2021],["Bangladesh", 1000, 2021],["England", 2000, 2021],["India", 3000, 2021],["Srilanka", 1500, 2021]] # dataframe dataFrame = pd.DataFrame(data, columns=["Team","Rank_Points", "Year"]) # plotting the dataframe dataFrame.plot(x="Team", y=["Rank_Points","Year" ], kind="line", figsize=(10, 9)) # displaying line graph mp.show()
Output
This will produce the following output −
- Related Articles
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- Python - How to plot a Pandas DataFrame in a Bar Graph
- Python - Draw a Scatter Plot for a Pandas DataFrame
- Python Pandas - Plot multiple data columns in a DataFrame?
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Python - Plot a Pie Chart for Pandas Dataframe with Matplotlib?
- Frequency plot in Python/Pandas DataFrame using Matplotlib
- How to plot an area in a Pandas dataframe in Matplotlib Python?
- Annotating points from a Pandas Dataframe in Matplotlib plot
- How to plot a Pandas Dataframe with Matplotlib?
- How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?
- How to plot a graph in Python?
- How to plot a bar graph in Matplotlib from a Pandas series?
- How do you plot a vertical line on a time series plot in Pandas?
- Python – Create a new column in a Pandas dataframe

Advertisements