Expand json data in a column inside dataframe


I know there is a way to expand the columns without extracting and joining/concatenating/appending data.

I have this json data which I’ve already normalized but I have a column that has a nested json:
Image of issue

So what I want to do is to expand this json data in a way that adds columns automatically in the dataframe without indexing since the data inside that column doesn´t have any key to pair, so it should be by position/row only.

What could I do to unnest it?

Update: In a previous step I’ve already normalized it:

response1 = requests.get(url1, params=params1, headers=headertoken)
textresponse1 = response1.text
   if "El contrato enviado no tiene envios registrados." in textresponse1:
textresponse1 = json.loads(response1.text)
response1_df = pd.json_normalize(textresponse1['envios'])
enviosdf = pd.concat([enviosdf,response1_df])

Problem is that, after this, the column ‘bultos’ is another json. Which when you try to normalize it, this happens:

0   {'kilos': 0.0025, 'IdDeProducto': 'ysyHhBHttHd...
1   {'kilos': 0.0025, 'IdDeProducto': 'QNEOqaNXtsi...
2   {'kilos': 0.0025, 'IdDeProducto': 'V7b3D7xaSur...

The normalization doesn’t normalize it nor expands it.

Asked By: Matias Tiberio



you should use explode before json_normalize because they are lists:

Answered By: Clegane
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.