-2

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:

enter image description here

1

1 Answer 1

3

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. Apologies but I am an apprentice for this. I used the above code and it seems like "undefined name df" does exist
Then instead of df put the name of your dataframe. For example if your dataframe is called hello replace df with hello.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.