0

I'm new to python. I have a simple DataFrame with a .json string I'd like to unnest.

import pandas as pd
df = pd.DataFrame([None, {'name': 'Charlie'}], columns=['A'])
pd.json_normalize(df, record_path=['A'], meta=['name'])

The following is giving me a "TypeError: string indices must be integers" error.

I have not had any luck with similar fixes such as making my df into a dict[1] or by using a lambda function[2].

[1] Python: json normalize "String indices must be integers" error

[2] Pandas json_normalize and null values in JSON

1
  • I wanted the column to be replace by the values. Thanks @not_speshal that's correct! Commented May 5, 2022 at 17:56

1 Answer 1

1

Try:

df = pd.json_normalize(df["A"].fillna("").apply(dict).tolist())
Sign up to request clarification or add additional context in comments.

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.