0
test = pd.DataFrame({"fruit":["apple","banana","melon", "grape"], "num":[1, 2, 3, np.nan], "human":["kim","ju", "Lee", "Gyeong"]})
test[test.isna().any(axis=1)].loc[:, "num"] = 4
test

It is very simple code. I want to change the row [grape, np.nan, "Gyeong"] to ["grape", 4, "Gyeong"]. However, it does not work. It does not change at all.. haha

How can I solve this problem?

hyemin ju
  • 3
  • 1
  • Dont chain. Just `test.loc[test.isna().any(axis=1), "num"] = 4` – Quang Hoang Nov 03 '21 at 03:02
  • https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.fillna.html – Riley Nov 03 '21 at 03:03
  • This should give a SettingWithCopyWarning as you are attempting to assign values to a copy of a slice. That said it may be one of the many [exceptions](https://github.com/pandas-dev/pandas/issues/18752) that are not covered. – Henry Ecker Nov 03 '21 at 03:20

1 Answers1

0

Try this:

df.iloc[[3], :] = ["grape", 4, "Gyeong"]