I am trying to replace words in a sentence in dataframe by a dictionary. How can I replace the original dataframe?
The dictionary : rep_vocab contains {wrong words: correct words}
dataframe: data_test
column['question1'] the sentences
column['d5'] contains a set of words which is misspelling in the sentences.i use this column to quickly locate the row of sentences which has wrong words.
My code:
data_test.loc[data_test['d5']!=set()['question1'].replace(rep_vocab,regex=True)
It returns the right result, but the original value in dataframe doesn't change.
I tried other ways like use inplace=True
, but it raised a 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