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'])