0

I've got a dataframe as in the image:

enter image description here

I'd like to transform that into a dataframe similar to the following:

enter image description here

But, in the second image, instead of having (0,1,2...) as index, I want to keep card_id as index - or as a column, whatever.

The second image is obtained applying pd.json_normalize in the first df's card_fields column.

I did find something similar in this question, but in there we start with a dictionary, instead of a dataframe, as in my case, so the proposed solution is not directly translatable to my case without doing a lot of manipulation.

Davi Alefe
  • 115
  • 10
  • 1
    `pd.concat([df.reset_index()[['card_id']], pd.json_normalize(df['card_fields'])], axis=1])` – Emma Feb 17 '22 at 03:15

1 Answers1

3

try pd.json_normalize(df['card_fields']).set_index(df.index)? df is the dataframe from image 1.

CJR
  • 76
  • 4