Both the .loc and .contains functions return a dataframe object. The pandas documentation states that to reassign a value to each row in the column, I should use .loc, but when combined with .contains I get this warning:
A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
However, the process works and I get the desired value reassignment for each row in the dataframe's column. How can I avoid this warning?
#works
df.loc[df["matchType"]=='duo',["matchType"]]='duo'
#warning thrown but still works
df.loc[df["matchType"].str.contains('duo'),["matchType"]]='duo'