Plot Dataset to Display Uptrend using Python Pandas



Upward pattern displayed by Time Series Analysis is what we call Uptrend. Let’s say the following is our dataset i.e. SalesRecords.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\SalesRecords.csv")

Casting column to datetime object −

dataFrame['Date_of_Purchase'] = pd.to_datetime(dataFrame['Date_of_Purchase'])

Create the plot for uptrend −

dataFrame.plot()

Example

Following is the 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\SalesRecords.csv")
print("Reading the CSV file...\n", dataFrame)

# casting column to datetime object
dataFrame['Date_of_Purchase'] = pd.to_datetime(dataFrame['Date_of_Purchase'])

dataFrame = dataFrame.set_index('Date_of_Purchase')

# Creating the plot
dataFrame.plot()
plt.show()

Output

Following is the output −

Updated on: 2021-10-01T11:27:48+05:30

142 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements