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
CodePudding user response:
Try:
df = pd.json_normalize(df["A"].fillna("").apply(dict).tolist())