python - parsing a dictionary in a pandas dataframe cell into new row cells (new columns) -


i have pandas dataframe contains 1 column containing cells containing dictionary of key:value pairs, this:

{"name":"test thorton","company":"test group","address":"10850 test #325\r\n","city":"test city","state_province":"ca","postal_code":"95670","country":"usa","email_address":"test@testtest.com","phone_number":"999-888-3333","equipment_description":"i'm big red truck\r\n\r\nrsn# 0000","response_desired":"week","response_method":"email"} 

i'm trying parse dictionary, resulting dataframe contains new column each key , row populated resulting values each column, this:

//before  1  2  3  4  5  b  c  d  {6:y, 7:v}  //after  1  2  3  4  5           6  7  b  c  d  {6:y, 7:v}  y  v 

suggestions appreciated.

consider df

df = pd.dataframe([         ['a', 'b', 'c', 'd', dict(f='y', g='v')],         ['a', 'b', 'c', 'd', dict(f='y', g='v')],     ], columns=list('abcde'))  df 

enter image description here


use apply(pd.series)

df.e.apply(pd.series) 

enter image description here


assign this

df[['f', 'g']] = df.e.apply(pd.series) df.drop('e', axis=1) 

enter image description here


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -