Previously, I read from a CSV file and got the min, max and average of my data in the CSV file. I'm trying to read the same data from a JSON file, and write output to CSV, but I'm not understanding how to do it. Any help is greatly appreciated. My JSON file is as follows:
{
"data": [
{
"time": "2015-10-14 15:01:10",
"values": {
"d1": 3956.58,
"d2": 0,
"d3": 19,
"d4": 6.21,
"d4": 105.99,
"d5": 42,
"d6": 59.24
}
},
{
"time": "2015-10-14 15:01:20",
"values": {
"d1": 3956.58,
"d2": 0,
"d3": 1,
"d4": 0.81,
"d5": 121.57,
"d6": 42,
"d7": 59.24
} .. ..
The code that I've so far is:
df = pd.read_json('data.json', convert_dates = True) df['time'] = [pd.to_datetime(d) for d in df['time']] df = df.set_index('time') hourly_stats = d.groupby(pd.TimeGrouper('H')) print((hourly_stats).agg([np.mean, np.min, np.max])) ((hourly_stats).agg([np.mean, np.min, np.max])).to_csv('file.csv')