I have a dataframe like this:
date message
05/01/2017 field1=aaaa&field2=bbbb&field3=cccc
05/02/2017 field1=aaaa&field2=bbbb&field3=cccc
I want to transform it like this:
date field1 field2 field3
05/01/2017 aaaa bbbb cccc
05/02/2017 aaaa bbbb cccc
But I'm not being able to. This is my code until now:
def split_log_fields(x):
date = x[0]
subscription = x[2][x[2].index('=')+1:]
user_id = x[3][x[3].index('=')+1:]
status = x[4][x[4].index('=')+1:]
return [[date],[subscription],[user_id],[status]]
a = pandas.read_csv(WEBPUSH_SUBSCRIBERS_FILE_NAME,sep='#',header=None)
b= a[1].str.split('&', 2,expand=True)
c = pandas.concat([a,b], axis=1, ignore_index=True)
d = c.apply(split_log_fields,axis=1).to_frame()
The problem is that d is not being separated by the right fields. d is like this now:
field
[[05/01/2017], [aaaa],[bbbb],[cccc]]
Pandas is not splitting the list of lists in different fields.
How can I fix this?