'unable to parse using pd.json_normalize, it throws null with index values
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 |
Solution 1:[1]
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'])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rabinzel |
