I want just want to loop through the array of json objects, and get the values of 'box'.....
I have a DataFrame which looks like this
img facesJson
0 2b26mn4.jpg [{'box': [57, 255, 91, 103], 'confidence': 0.7...
1 cd7ntf.jpg [{'box': [510, 85, 58, 87], 'confidence': 0.99...
2 m9kf3e.jpg [{'box': [328, 78, 93, 123], 'confidence': 0.9...
3 b4hx0n.jpg [{'box': [129, 30, 38, 54], 'confidence': 0.99...
4 afx0fm.jpg [{'box': [86, 126, 221, 298], 'confidence': 0....
and the column 'facesJson' (dstype = object) contain array of json objects which look like this:
[
{
"box":[ 158,115,84,112 ],
"confidence":0.9998929500579834,
},
{
"box":[ 404,105, 86,114 ],
"confidence":0.9996863603591919,
}
]
when i run this code
for index,row in df.iterrows():
df = pd.json_normalize(row['facesJson'])
print(len(df))
i get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-53-8be848c6d44a> in <module>()
1 for index,row in savedList.iterrows():
----> 2 df = pd.json_normalize(row['facesJson'])
3 print(len(df))
1 frames
/usr/local/lib/python3.6/dist-packages/pandas/io/json/_normalize.py in <genexpr>(.0)
272
273 if record_path is None:
--> 274 if any([isinstance(x, dict) for x in y.values()] for y in data):
275 # naive normalization, this is idempotent for flat records
276 # and potentially will inflate the data considerably for
AttributeError: 'str' object has no attribute 'values'