My original output will looks like this
quarterly_churn_count["Churn"]
Out[35]:
year quarter
2008 1 1070
2013 1 31
2 47
3 57
4 59
2014 1 33
2 43
3 49
4 37
Name: Churn, dtype: int64
I am using this below code to convert to json format
results = [{'quarterly_churn_count["Churn"]' : quarterly_churn_count["Churn"] }]
final = pd.DataFrame(results)
final = final.to_json(orient='records')
print(final)
My output will be like this after converting to json
[
{
"quarterly_churn_count[\"Churn\"]": [
1070,
31,
47,
57,
59,
33,
43,
49,
37
]
}
]
I am not able to get the key like year, quarter. I am getting only values after converting that to to_json with orient value records.
My expected results would be like this, for example
quarter[
{
year : 2008
quarter : 1
value :518
}
{
year :1999
quarter : 4
value : 89
}
]