I have pandas dataframe like this (single column):
request_headers
0 {'name': 'name1', value: 'value1'}
0 {'name': 'name2', value: 'value2'}
.....
Would like to aggregate many such records to a single record with a column which is a list of the above directories, like this:
request_headers
0 [{'name': 'name1', value: 'value1'}, {'name': 'name2', value: 'value2'}]
How to do that ? (tried with agg({col: lambda x: ",".join(x)})
and few similar but failing)
Thanks,
Update: Answer somebody provided is not correct, it's easy to do it for non-dict values, but for dict values we got error that it's unhashable
. So the question is still valid. The problem here is that column value is a dict.
Update2: OK, sorry, one more example:
details = {
'request_headers' : [{"name": "name1", "value": "value1"}, {"name": "name2", "value": "value2"}],
}
df = pd.DataFrame(details)
df.groupby(df.index).agg(list)
is giving me:
0 [{'name': 'name1', 'value': 'value1'}]
1 [{'name': 'name2', 'value': 'value2'}]
While i would like to get:
0 [{'name': 'name1', 'value': 'value1'},{'name': 'name2', 'value': 'value2'}]
So technically it's not even groupby, but some concatenation ? (i have actually exploded my df before and need to "implode" it now)