I'm using pandas json normalize to transform a json into a pandas dataframe. This is the json that's giving me problems:
{
"P48PrecTer":{
"@xmlns":"http://sujetos.esios.ree.es/schemas/2010/05/31/P48PrecTer-esios-MP/",
"IdSesion":"16",
"SeriesTemporales":{
"IdentificacionSeriesTemporales":"STP0",
"TipoNegocio":"A10",
"UnidadPrecio":"EUR:MWH",
"Periodo":[
{
"IntervaloTiempo":"2020-07-12T00:00Z/2020-07-12T01:00Z",
"Resolucion":"PT60M",
"Intervalo":{
"Pos":"1",
"PrecioBaj":"25.20"
}
},
{
"IntervaloTiempo":"2020-07-12T03:00Z/2020-07-12T11:00Z",
"Resolucion":"PT60M",
"Intervalo":[
{
"Pos":"1",
"PrecioSub":"27.36"
},
{
"Pos":"2",
"PrecioBaj":"23.50"
},
{
"Pos":"8",
"PrecioBaj":"16.90"
}
]
},
{
"IntervaloTiempo":"2020-07-12T12:00Z/2020-07-12T16:00Z",
"Resolucion":"PT60M",
"Intervalo":[
{
"Pos":"1",
"PrecioSub":"29.90"
},
{
"Pos":"4",
"PrecioBaj":"15.75"
}
]
}
]
}
}
}
I'm using this piece of code:
prueba=pd.json_normalize(body,record_path=['P48PrecTer','SeriesTemporales','Periodo','Intervalo'], meta=[['P48PrecTer','IdSesion'], ['P48PrecTer','SeriesTemporales','Periodo','IntervaloTiempo']])
I expect something with a csv structure. However, I get this:
0|P48PrecTer.IdSesion|P48PrecTer.SeriesTemporales.Periodo.IntervaloTiempo
Pos|06|2020-07-12T22:00Z/2020-07-12T23:00Z
PrecioBaj|06|2020-07-12T22:00Z/2020-07-12T23:00Z
PrecioSub|06|2020-07-12T22:00Z/2020-07-12T23:00Z
{'Pos': '1', 'PrecioBaj': '4.41', 'PrecioSub': 'null'}|06|2020-07-13T00:00Z/2020-07-13T03:00Z
{'Pos': '2', 'PrecioBaj': '9.00', 'PrecioSub': 'null'}|06|2020-07-13T00:00Z/2020-07-13T03:00Z
{'Pos': '3', 'PrecioBaj': '10.10', 'PrecioSub': 'null'}|06|2020-07-13T00:00Z/2020-07-13T03:00Z
I am guessing that the problem may be the list associated with 'Periodo' key, as I've worked with other json with a similar structure and didn't have any problem. Is there any way to get to the point I'm aiming? Thank you.