1

I am trying to normalize a very simple JSON structure.

data = [{"pedido": {"situacao": "OK", ....}}, {"pedido": {"situacao": "NOK", ...}}]
rs = json_normalize(data, 'pedido', [['pedido', 'situacao']])

I would like to get just the index and another column called pedido.situacao. There is a bunch of other field on json but I want to get only situacao:

0 pedido.situacao
0  situacao              OK
1  situacao             NOK

It seens there is a extra column with "0"as label.

2 Answers 2

1

We can do

df=pd.concat(pd.DataFrame(x) for x in data)
         pedido
situacao     OK
situacao    NOK

Update

df=pd.concat([pd.DataFrame(x) for x in data],keys=range(len(data))).unstack(level=1)
df.columns=df.columns.map('.'.join)
df
  pedido.situacao
0              OK
1             NOK
Sign up to request clarification or add additional context in comments.

1 Comment

I want only a single column called pedido.situacao
0

You can just do this:

rs = pd.json_normalize(data)
print(rs[['pedido.situacao']])

  pedido.situacao
0              OK
1             NOK

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.