I have a column authors in a dataframe df where the values are first in a dictionary and then the dictionary is added to a list. The list in then stored in a column. Such as the following:
[{'family': 'Yaisy',
'given': 'Lisa',
'affiliation': [{'name': 'Department of Sciences, Faculty Sciences, University of Science'}]},
{'family': 'Kite',
'given': 'Hume',
'affiliation': [{'name': 'Department of Sciences, Science and Technology'}]},
{'family': 'Jones',
'given name': 'Mike',
'localId': 'aza',
'affiliation': [{'name': 'Department of Health, Science and Technology'}]},
{'family': 'abc',
'given name': 'xyz',
'affiliation': [{'name': 'Health Sciences, University of Science'}]}]
I want to break this list into different columns with the keys as column names and the values as columns values. Since the keys have duplicate names, it is ok for me to just add 1,2,3 as suffix for each column name. I tried the solution suggested in this question
df.join(pd.json_normalize(df.authors))
However, I first need to change the list into a simple dictionary and then use the above the solution. So I tried flattening the list to get the dictionaries and store them in the same column with:
df.author = [y for x in df.author for y in x]
But here I get the error that length of values does not match length of index.
Can anyone kindly help me in solving this issue? Thanks!