I am trying to replace a string found in a column with
file1_backup_df.loc[file1_backup_df['CustName'].str.contains('bbb', case=False), 'CustomerName'] = 'Big Boy Booty'
Now the above works on a single dataframe (file1_backup_df). But I am combining dataframes like this;
frames = [add_backup_name(), file1_backup_df]
final_df = pd.concat(frames)
I'd like to perform the very first line of code on final_df
. But I can't.
It grumbles about
__setitem__
indexer = self._get_setitem_indexer(key)`.
ValueError: Cannot mask with non-boolean array containing NA / NaN value
Is there a way to replace strings in a column of my combined df?
I tried this but no go;
pd.concat(frames, ignore_index=True)
EDIT
Looks like this may have done it. Testing.
CodePudding user response:
It seems that the column CustomerName
holds some NaN
values, so you need to set na=False
in pandas.Series.str.contains
:
Try this :
final_df.loc[final_df['CustName'].str.contains('bbb', case=False, na=False), 'CustomerName'] = 'Big Boy Booty'