Split nested column into new columns
Maybe this helps.
import pandas as pd
data = [{"institution":"some_institution",
"startMonth":1,
"startYear":2563,
"course":"any",
"id":1111,
"formation":"any",
"endMonth":12,
"endYear":2556,
"status":"complete"}]
l = next(item for item in data)
df = pd.DataFrame(l, index=[0])
df
My dataframe has a nested column (people_info) that contains cells like the sample below.
[{"institution":"some_institution","startMonth":1,"startYear":2563,"course":"any","id":1111,"formation":"any","endMonth":12,"endYear":2556,"status":"complete"}]
As far I know this can be solved using dictionary/json concepts.
I'm trying to split this column in new columns, considering that each key of this nested cell will be a new column with their respective values.
I tried json_normalize, but I'm getting this error: "AttributeError: 'str' object has no attribute 'values'"
I tried to transform those cells in a dict, but I never was able to make python understand that "institution" is a key and "some_institution" is a value in this created dict. It's seems python understand the whole cell as a string.
Can you help me? If I wasn't clear, please tell me. Tks!