0

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)
NineWasps
  • 2,081
  • 8
  • 28
  • 45
  • Please include how pandas data originally looks and even desired results. *Data in the strings will be ascending* is not too clear. Do you meant the numeric 1's and 0's? – Parfait Jul 13 '16 at 16:44
  • json doesnt have an order – GMarsh Jul 14 '16 at 02:40

0 Answers0