I have a question regarding writing json from a python pandas dataframe.
I am reading the data from a csv file with pandas to a dataframe, add some calculated field and then aggregate the data. The dataframe looks the like this:
country city date chng population
0 USA NewYork 2020-01-01 3.55 20.15
1 USA NewYork 2021-01-01 -1.58 19.84
2 UK London 2020-01-01 1.38 9.30
3 UK London 2021-01-01 1.31 9.42
Now I wanna create a json file, which looks somehow like this:
{
"metrics": [
{
"metric": "data.usa.newyork.change",
"value": 3.55
},
{
"metric": "data.usa.newyork.population",
" value ": 20.15
}
],
"metricTime": "2020-01-01",
"region": "X"
},
{
"metrics": [
{
"metric": "data.usa.newyork.change",
"value": -1.58
},
{
"metric": "data.usa.newyork.population",
" value ": 19.84
}
],
"metricTime": "2021-01-01",
"region": "X"
},
{
"metrics": [
{
"metric": "data.uk.london.change",
"value": 1.38
},
{
"metric": "data.uk.london.population",
" value ": 9.30
}
],
"metricTime": "2020-01-01",
"region": "X"
},
{
"metrics": [
{
"metric": "data.uk.london.change",
"value": 1.31
},
{
"metric": "data.uk.london.population",
" value ": 9.41
}
],
"metricTime": "2021-01-01",
"region": "X"
},
Does someone can help me?