I have a DataFrame like this and I want a result shown below:
Country, ESG, Pillar, Series, 2012, 2013, Last Updated
Nepal, Social, health, clean fuels, 24.6, 26.1, 05/01/2021
Nepal, Environment, Food, agriculture,30.0, 28.62, 05/01/2021
Nepal,Environment,Food, land, 28.0, 27.0, 05/01/2021
I want to upload this data to MongoDB and I want the structure in the format shown below as a python snippet. I tried with groupby method however, I did not achieve the desired output.
{
'Country': 'Nepal',
{
'ESG': 'Social',
'Pillar': 'health',
'clean fuels:
{
'2012': 24.6,
'2013': 26.1
}
},
'last Updated': 05/01/2021
}
Can somebody help me with this problem?