Separate Pd Dataframe Rows That Are Dictionaries Into Columns
I am extracting some data from an API and having challenges transforming it into a proper dataframe. The resulting DataFrame df is arranged as such: Index Column 0 {'email
Solution 1:
One naive way of doing this is as below:
inp = [{'email@email.com': [{'action': 'data', 'date': 'date'}, {'action': 'data', 'date': 'date'}]}
, {'different-email@email.com': [{'action': 'data', 'date': 'date'}]}]
index = 0
df = pd.DataFrame()
foreach in inp: # iterate through the list of dictsfor k, v in each.items(): #take each key value pairsfor eachv in v: #the values being a list, iterate through eachprint (str(eachv))
df.set_value(index,'Column1',k)
df.set_value(index,'Column2',str(eachv))
index += 1
I am sure there might be a better way of writing this. Hope this helps :)
Post a Comment for "Separate Pd Dataframe Rows That Are Dictionaries Into Columns"