Hi I have two pandas series similar to below
PnL
Product Name Price
Company A Orange 3000
Company B Apple 2000
Grapes 1000
Tax
Product Name Price
Company A Orange 100
Company B Apple 100
Grapes 10
I would like to transform the pandas series into the following JSON format
{'PnL':{'Company A':{'productName':'Orange','price':3000},
'Company B':[{'productName':'Apple','price':2000},
{'productName':'Grapes','price':1000}]
},
'Tax':{'Company A':{'productName':'Orange','price':100},
'Company B':[{'productName':'Apple','price':100},
{'productName':'Grapes','price':10}]
}
}
I have tried to use the code below
convertedJson = json.dumps([{'company': k[0], 'productName':k[1],'price': v} for k,v in df.items()])
but I cannot form the JSON which I want to produce. Thank you for your help