Let me preface this question by noting that the combined column is not a dictionary. The resulting dataframe has square brackets within the 'combined' column - so it appears like a list within the dataframe int he format [key1:value1, key2:value2, etc].
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']
Tried to turn the dataframe into a dictionary per row, but got stuck converting that into a list.
test['combined'] = test.to_dict(orient='records')
The resulting new column doesn't need to be an actual list type. It could be a string.
Previously asked this question here but wanted to clarify the question in the title in this question. How to Create a List from a Dictionary within a DataFrame in Python
Found the following closely related questions and tried derivations of them which gets me half the way but can't seem to get exactly the right format.