I have a CSV file which contains a dict value.
Test.CSV
id,name,contact,Location
1,Julie,"[{""name"":""Jenny Brown"",""relation"":""mother"",""number"":2113131313},{""name"":""Jorge"",""relation"":""brother"",""number"":121313131}]",US
2,Jim,"[{""name"":""Sana"",""relation"":""sister"",""number"":83279131}]",UK
I want to normalize this CSV. Expected output:
id , name, contact_name,contact_realation,contact_number,location
1,Julie,Jenny Brown,mother,2113131313,US
1,Julie,Jorge,brother,121313131,US
2,Jim,Sana,sister,83279131,UK
I have loaded the data using CSV reader but I am not able to normalize the contact value. How can I do that?
csvfile = csv.reader(open(filename, encoding="utf8"))
So far I tried this:
df=pd.read_csv(filename, converters={'contact':json.loads}, header=0)
contact_df = pd.io.json.json_normalize(df['contact'])
but getting the below error:
AttributeError: 'list' object has no attribute 'values'