Thank you for your time visiting my post. I have the following dataframe below:
df1
col1 col2
1 virginia is cold, canada is cold too virginia is cold, canada is cold too
2 florida, virginia, washington are good florida, virginia, washington are good
3 georgia, alabama, virginia are hot virginia is cold, canada is cold too
4 virginia, ohio, new castle are great hawaii, nebreska is wonderful
5 hawaii, nebreska is wonderful virginia, ohio, new castle are great
Also, I have a list containing a string:
lst = ['virginia', 'hot', 'too']
I want to replace the string in the entire dataframe with "xxxxxx" if it matches one of the strings in the list. For instance, my dataframe would look like this after replacement:
df1
col1 col2
1 xxxxxx is cold, canada is cold xxxxxx xxxxxx is cold, canada is cold xxxxxx
2 florida, xxxxxx, washington are good florida, xxxxxx, washington are good
3 georgia, alabama, xxxxxx are xxxxxx xxxxxx is cold, canada is cold xxxxxx
4 xxxxxx, ohio, new castle are great hawaii, nebreska is wonderful
5 hawaii, nebreska is wonderful xxxxxx, ohio, new castle are great
So far, I have tried but it does not work:
df1 = df1.replace(lst, "xxxxxx")
