- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plot the dataset to display Horizontal Trend – Python Pandas
Horizontal trend is also called Stationery trend. Let’s say the following is our dataset i.e. SalesRecords3.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\SalesRecords3.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\SalesRecords3.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 −
Advertisements