0

Consider the following data

d = {'color' : pd.Series(['white', 'blue', 'orange']), 
    'second_color': pd.Series(['white', 'black', 'blue']),
    'value' : pd.Series([1., 2., 3.])}

df = pd.DataFrame(d)

Now suppose I want to replace 'white' in columns color and second_color with NaN , in place. I know that one way to do this is

df = df.replace('white', np.NaN)

    color   second_color  value
0   NaN     NaN           1.0
1   blue    black         2.0
2   orange  blue          3.0

But why is it that when I try

df[['color', 'second_color']].replace('white', np.NaN, inplace=True)

instead I don't get the desired results? That is, 'white' doesn't get replaced in df.

PollPenn
  • 723
  • 2
  • 8
  • 18

0 Answers0