I am trying to get the unique values from a list into a different column using 'set' function in the python 3. However I am getting the error: "TypeError: 'Series' objects are mutable, thus they cannot be hashed". What am I doing wrong here?
Sample Data:
id,food 1,food 2,food 3
1,,apples,mango
2,oranges,grapes,oranges
3,bananas,,apples
Code:
df = pd.read_csv('food.csv')
df
# pass
list(set(['apples','apples','oranges']))
# answers: ['apples', 'oranges'] #working
# fails if I pass in a dataframe columns. Why?
df['food_all'] = list(set([df['food 1'],df['food 2'],df['food 3']]))
df['food_all']
output like (ignoring spaces/null values...etc):
id,food_all
1,['apples','mango']
2,['oranges','grapes']
3,['bananas','apples']