'Plotting Time Series using pandas
I have a .csv file containing time series data with headers like Description, Date and Values. I am looking to make a line graph for this time series in such that 'Values' are in Y-axis and 'Date' in X-axis.
Sample data below:
Description Date Values
AGN_MXN_360 20190131 4.134
AGN_MXN_360 20190201 3.00
AGN_MXN_360 20190205 7.68
AGN_MXN_360 20190206 3.25
....
....
....
AGN_MXN_360 20190920 3.7941
It should look like the below:
Solution 1:[1]
Try set your date columns as the index, then plot the values column.
import pandas as pd
# import the csv file
df = pd.read_csv('mycsvfile.csv')
# make sure the time column is actually time format
df['Date']=pd.to_datetime(df['Date'])
# set time as the index
df.set_index('Date',inplace=True)
# plot
df['values'].plot()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |