How to draw time-series chart by using Python? Since in the data set, time is split as year, and period (which is Month like M1, M2).
I am using matplotlib, but don't know how to split the time.
The codes I wrote to get the dataļ¼ import pandas as pd from pandas import DataFrame data1 = pd.read_csv('CUUR0000SA0.txt', header = None) data2 = pd.read_csv('SUUR0000SA0.txt', header = None) data = pd.concat([data1, data2]) data.columns = ["a"] data = DataFrame(data) print(data.head())
However, the output dataframe has only one column.
Part of the the data set looks like this:
+-------------+------+--------+---------+-----------+
| series id | year | period | value | footnotes |
+-------------+------+--------+---------+-----------+
| CUUR0000SA0 | 2014 | M12 | 234.812 | |
| CUUR0000SA0 | 2014 | M11 | 236.151 | |
| CUUR0000SA0 | 2014 | M10 | 237.433 | |
| CUUR0000SA0 | 2014 | M09 | 238.031 | |
| CUUR0000SA0 | 2014 | M08 | 237.852 | |
The chart should explain the trend of values using a graph according to the time periods. But I don't know how to transfer it into the right format first.
df.plot()get what you need? How aboutdf.sort_values(['year', 'period']).plot(x='period', y='value')? - johnchase