0

I used this method to fill in the missing values in a certain range of a column. It gives me no error but does not actually replace the missing values. Something might be wrong with the logic of the code. I had the same number of NaNs before replacing.

code:

Lan = data["Group"].loc[57:70]
Lan.replace(np.nan, "Lan", inplace=True)
Act = data["Group"].loc[89:102]
Act.replace(np.nan, "Act", inplace=True)
data["Group"].isna().sum() # 28
  • Please, could you put the code into the question directly via markdown? How many NaNs did you have before replacing? – Vovin May 07 '23 at 22:45
  • Would you provide us with a **minimal reproducible example** and possibly a sample dataset? – Mario May 08 '23 at 01:19
  • You need use `fillna`, ie, `df.loc[0:3, 'Group'] = df['Group'].fillna('Lan')` – Ynjxsjmh May 08 '23 at 02:07
  • You're trying to replace a floating point number, NaN, with a string; if the column type is string as well, there won't be any NaNs in the column, so nothing can be replaced. Try replacing `None` instead; but `fillna` is better. – 9769953 May 08 '23 at 16:22

0 Answers0