1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| import json import pandas as pd import matplotlib.pyplot as plt def format_dataframe(df): df.columns = ['date','value'] df.sort_values(by='date',inplace=True) df.set_index('date',inplace=True) return df
with open('data.json') as f : data = json.load(f) ''' { "dataset": { "dataset_code": "M550_SALES", "transform": null, "frequency": "monthly", "id": 35366971, "data": [ [ "2016-06-30", 64.0 ], [ "2016-05-31", 163.0 ] ] } } ''' df = pd.DataFrame(data['dataset']['data']) df = format_dataframe(df) df.plot(figsize=(16, 6)) plt.show()
|