I'm trying to convert my dataframe from this:
import pandas as pd
test = pd.DataFrame({'apples':['red','green','yellow'], 'quantity':
[1,2,3],'tasteFactor':['yum','yum','yuck']})
apples quantity tasteFactor
0 red 1 yum
1 green 2 yum
2 yellow 3 yuck
To this format, which is combining keys with values in each row into a new column:
apples quantity tasteFactor combined
0 red 1 yum ['apples':'red','quantity':'1','tastefactor':'yum']
1 green 2 yum ['apples':'green','quantity':'2','tastefactor':'yum']
2 yellow 3 yuck ['apples':'yellow','quantity':'3','tastefactor':'yuck']
I tried to turn the dataframe into a dictionary per row - but that didn't work. The resulting new column doesn't need to be an actual list type. It could be a string.
EDIT 1: Some people have marked this as duplicate and pointed it to creating a dictionary. BUT it's NOT a dictionary - I need the square brackets within the 'combined' column - so it appears like a list.