Plot the dataset to display Downtrend – Python Pandas


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

Casting column to datetime object −

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

Create the plot for downtrend −

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

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

dataFrame = dataFrame.set_index('Sold_On')

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

Output

This will produce the following output −

Updated on: 01-Oct-2021

57 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements