I have the following df:
Q4_1 Q4_2 Q4_3 Q4_4 \
130 far cry 4 NaN NaN NaN
131 grand theft auto Assassins Creed call of duty watch dogs
132 the elder scrolls v the witcher 3 dragon age dark souls
133 Uncharted Call of duty Deadpool Far cry
134 Monster Hunter: World Kingdom Hearts III Darksiders III NaN
135 Fallout 4 NaN NaN NaN
Q4_5 Q4_6 Q4_7 Q4_8 Q4_9 Q4_10
130 NaN NaN NaN NaN NaN NaN
131 NaN NaN NaN NaN NaN NaN
132 fallout assassins creed fallout 3 NaN NaN NaN
133 Grand theft auto NaN NaN NaN NaN NaN
134 NaN NaN NaN NaN NaN NaN
135 NaN NaN NaN NaN NaN NaN
I would like to replace similar strings by a unique identity string based on a list. So this would be the desired output:
Q4_1 Q4_2 Q4_3 Q4_4 \
130 far cry 4 NaN NaN NaN
131 grand theft auto Assassin's Creed call of duty watch dogs
132 the elder scrolls v the witcher 3 dragon age dark souls
133 Uncharted Call of duty Deadpool Far cry
134 Monster Hunter: World Kingdom Hearts III Darksiders III NaN
135 Fallout 4 NaN NaN NaN
Q4_5 Q4_6 Q4_7 Q4_8 Q4_9 Q4_10
130 NaN NaN NaN NaN NaN NaN
131 NaN NaN NaN NaN NaN NaN
132 fallout Assassin's Creed fallout 3 NaN NaN NaN
133 Grand theft auto NaN NaN NaN NaN NaN
134 NaN NaN NaN NaN NaN NaN
135 NaN NaN NaN NaN NaN NaN
So I already got a set of values that can be found:
list_assasins_creed = ['Assasin\'s Creed', 'Assassin\'s Creed', 'Assassins Creed', 'assasins creed', 'assassin\'s creed', 'assassins creed']
This values can be found in multiple columns (Q4_1..Q4_9)
I would like to replace those values by Assassin's Creed. I tried to use loc:
df_survey_Q4.loc[df_survey_Q4[['Q4_1', 'Q4_2', 'Q4_3', 'Q4_4', 'Q4_5', 'Q4_6', 'Q4_7', 'Q4_8','Q4_9', 'Q4_10']].isin(list_assasins_creed),['Q4_1', 'Q4_2', 'Q4_3', 'Q4_4', 'Q4_5', 'Q4_6', 'Q4_7', 'Q4_8','Q4_9', 'Q4_10']] = 'Assassin\'s Creed'
But I got this error:
KeyError: "None of [Index([ ('Q', '4', '_', '1'), ('Q', '4', '_', '2'),\n ('Q', '4', '_', '3'), ('Q', '4', '_', '4'),\n ('Q', '4', '_', '5'), ('Q', '4', '_', '6'),\n ('Q', '4', '_', '7'), ('Q', '4', '_', '8'),\n ('Q', '4', '_', '9'), ('Q', '4', '_', '1', '0')],\n dtype='object')] are in the [index]"
Any idea how can I do this?