i have dataframe like this:
id date value
1 2021-09-01 [{'value': 'Keyman', 'sum': 8932.199999999999}
{'value': 'Suluboya', 'sum': 5896.7499999999945}]
2 2021-10-01 [{'value': 'Atelier', 'sum': 5595.299999999992}
{'value': 'Atölye4D', 'sum': 3538.7299999999987}]
expected output:
idx date value sum
1 2021-09-01 Keyman 8932.199999999999
2 2021-09-01 Suluboya 5896.7499999999945
3 2021-10-01 Atelier 5595.299999999992
4 2021-10-01 Atölye4D 3538.7299999999987
i tried:
df = pd.json_normalize(df['value'][0])
this was for the first row only. It works but there is a lot of data than that and I believe there is a shorter way. I tried this too.
def only_dict(d):
return ast.literal_eval(d) if pd.notnull(d) else {}
dfy = json_normalize(df['value'].apply(only_dict).tolist()).add_prefix('_')
but i am getting this error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()