-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

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
  • 2
    Possible duplicate of [Pandas: plot multiple time series DataFrame into a single plot](https://stackoverflow.com/questions/38197964/pandas-plot-multiple-time-series-dataframe-into-a-single-plot) – pissall Sep 20 '19 at 10:42

1 Answers1

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()
SCool
  • 3,104
  • 4
  • 21
  • 49
  • 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 – user12010260 Sep 20 '19 at 11:52
  • Then instead of `df` put the name of your dataframe. For example if your dataframe is called `hello` replace `df` with `hello`. – SCool Sep 20 '19 at 12:23