I need to replace some column of a dataframe with NA's. I am able to do so partially however, some values in a column are not converted to NA's.
Here is an example dataframe you can work on:
df = pd.DataFrame({'away_score': {672: 2.0,
673: 1.0,
674: 2.0,
675: 2.0,
676: 1.0,
677: 1.0,
678: 2.0,
679: 1.0,
680: 1.0,
681: 2.0},
'home_score': {672: 2.0,
673: 2.0,
674: 3.0,
675: 0.0,
676: 0.0,
677: 2.0,
678: 2.0,
679: 1.0,
680: 2.0,
681: 2.0},
'match_id': {672: 273236,
673: 273234,
674: 273239,
675: 273231,
676: 273232,
677: 273238,
678: 273237,
679: 273240,
680: 273233,
681: 273235},
'match_status': {672: 'Finished',
673: 'Finished',
674: 'Finished',
675: 'Finished',
676: 'Finished',
677: 'Finished',
678: 'Finished',
679: 'Finished',
680: 'Finished',
681: 'Finished'}})
My code so far:
columns_to_fillna = ["match_status","home_score","away_score"]
for column in columns_to_fillna:
df[column] = df[column].apply(lambda row: df[column].replace(row,np.nan))
This somehow changes some rows for home_score and away_score column and some rows remain the same. What could be the issue here?