I need to add the column name as key value pair inside each cell
eg: {"colname": "Ship Mode label"}
How to do that in pandas?
>Solution :
A simple loop should work to update the dictionaries in place:
for col in df:
for s in df[col]:
s['colname'] = col
example input:
df = pd.DataFrame({'A': [{'a': 1, 'b': 2}], 'B': [{'a': 1, 'b': 2}]})
output:
A B
0 {'a': 1, 'b': 2, 'colname': 'A'} {'a': 1, 'b': 2, 'colname': 'B'}
