Home > Back-end >  unable to parse using pd.json_normalize, it throws null with index values
unable to parse using pd.json_normalize, it throws null with index values

Time:05-07

Sample of my data:

ID target
1 {"abc":"xyz"}
2 {"abc":"adf"}

this data was a csv output that i imported as below in python

data=pd.read_csv('location',converters{'target':json.loads},header=None,doublequote=True,encoding='unicode_escape')

data=data.drop(labels=0,axis=0)
data=data.rename(columns={0:'ID',1:'target'})

when I try to parse this data using

df=pd.json_normalize(data['target'])

i get Empty dataframe

0
1

CodePudding user response:

You need to change the cells from strings to actual dicts and then your code works. Try this:

df['target'] = df['target'].apply(json.loads)
df = pd.json_normalize(df['target'])
  • Related