-1

I have a DataFrame, where I want to apply filter in first column and then replace a number in 6th column with np.nan.

I also want to do these changes without taking the filter out of DataFrame. because I want theenter image description here changes to be part of same DataFrame.

For example. if ID=1, I want to replace "f" with np.nan

  • Possible duplicate of [Pandas DataFrame: replace all values in a column, based on condition](https://stackoverflow.com/questions/31511997/pandas-dataframe-replace-all-values-in-a-column-based-on-condition) – Vaishali Jan 31 '18 at 01:38

1 Answers1

0

This does what you want, but I suggest you read up on Indexing and Selecting Data.

df.loc[df['ID'] == 1, 'f'] = np.nan
jpp
  • 159,742
  • 34
  • 281
  • 339