Create time series plot in python where date is the header

Dear all,

I am trying to plot a quick time series from the following data_accounts:

                     Indicator Name Indicator Code       2011       2014  \
1552            Account (% age 15+)    account.t.d  22.260538  30.277130   
1553    Account, female (% age 15+)  account.t.d.2  13.775815  22.079350   
1557      Account, male (% age 15+)  account.t.d.1  30.377668  37.790764   
2328            Account (% age 15+)    account.t.d  59.852112  71.997162   
2329    Account, female (% age 15+)  account.t.d.2  57.535416  70.323524   
...                             ...            ...        ...        ...   
140457  Account, female (% age 15+)  account.t.d.2  23.337385  33.247768   
140461    Account, male (% age 15+)  account.t.d.1  19.392923  38.135086   
141232          Account (% age 15+)    account.t.d  39.651211  32.389252   
141233  Account, female (% age 15+)  account.t.d.2  37.124409  28.979719   
141237    Account, male (% age 15+)  account.t.d.1  42.545574  35.953903   

             2017  Unnamed: 7  
1552    37.165211         NaN  
1553    25.635403         NaN  
1557    48.328518         NaN  
2328    73.693977         NaN  
2329    71.484467         NaN  
...           ...         ...  
140457  40.278877         NaN  
140461  51.680923         NaN  
141232  55.285137         NaN  
141233  51.664925         NaN  
141237  59.227501

I tried the following

plot_accounts = matplot(colnames(data_account[-1]), t(data_account[-1]), type="l", xlab="year", ylab="percent")


legend("topright", legend=data_account['Indiactor Name'], col=5:8, lty=5:8)

I have in total 8 columns with some other data.

Could someone please help me?

is the data in a csv file? are you using Pandas, NumPy and Matplotlib/Pyplot as plt?

When you create the df and use pd.read_csv() you could pass in the parameter index_col = 'Order Date' (or year or whatever).

This video on creating time series plots is brief and might be helpful for your case.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.