i have grouped the set of results and trying to convert that results to python with to_json method.
This is my code to convert my results to json. The results variable contains all the results.
results = {'main_category' : {'total_count' : total_count,'total_predicted_postive_count' : total_predicted_postive_count, 'total_predicted_negative_count' : total_predicted_negative_count ,
'total_predicted_postive_rate' : total_predicted_postive_rate, 'total_predicted_negative_rate' : total_predicted_negative_rate, 'high_predicted_positive_region' : high_predicted_positive_region,
'model_accuracy' : model_accuracy } }, { 'category' : [{ 'subcategory' : 'gender'}, [{'subcategory_name' : [{ 'subcategory_name' : 'male', 'churn_count' : male_churn_count, 'churn_rate' : male_churn_rate, 'retention_count' : male_retention_count,
'retention_rate' : male_retention_rate }] }] ] }
overall_results = pd.Series(results).to_json(orient='records')
print(overall_results)
After i convert this to json, my output will be like this
[
{
"main_category": {
"high_predicted_positive_region": 564,
"total_predicted_postive_count": 1481,
"model_accuracy": 1,
"total_predicted_postive_rate": 0.2212429041,
"total_predicted_negative_rate": 0.7787570959,
"total_count": 7032,
"total_predicted_negative_count": 5213
}
},
{
"category": [
{
"subcategory": "gender"
},
[
{
"subcategory_name": [
{
"churn_rate": 0.106363908,
"churn_count": 712,
"retention_count": 2658,
"subcategory_name": "male",
"retention_rate": 0.3970720048
}
]
}
]
]
}
]
But my expected output format should be like this
[
{
"main_category": {
"high_predicted_positive_region": 564,
"total_predicted_postive_count": 1481,
"model_accuracy": 1,
"total_predicted_postive_rate": 0.2212429041,
"total_predicted_negative_rate": 0.7787570959,
"total_count": 7032,
"total_predicted_negative_count": 5213
}
},
{
"category": [
{
"subcategory": "gender"
},
[
{
"subcategory_name": [
{
"subcategory_name": "male",
"churn_count": 712,
"churn_rate": 0.106363908,
"retention_count": 2658,
"retention_rate": 0.3970720048
}
]
}
]
]
}
]
inside the array of subcategory name, whatever order i mentioned in the results, it should display. But i am getting in a mixed order.
Where should i change according to that order. Any other way to get this same result format.