I need to write data to json
, but I want, that data in the strings will be ascending. But I get
"0987654321abcdef1234567890abcdef": {
"2014-06": 1,
"2016-05": 1,
"2016-09": 1,
"2016-03": 0,
"2015-02": 0,
"2016-01": 0
}
}
But I sort data using df.sort_values(['ID', 'date'])
And write
nielson = StringIO.StringIO()
output.groupby('ID').apply(lambda x: x.set_index('filtered_dates')['val'].to_dict()).to_json(nielson, orient='index')
with open('nielsen','w') as f:
json.dump(json.loads(nielson.getvalue()), f, indent=2)