1

for example i want to replace 'NAN' with 'dog' and 'cat'. like from 1-30 'Nan' should be replaced with 'dog' and from 40-100 it should be replaced by 'cat'. how am i supposed to do it

2 Answers2

1

Spilt your problem into smaller ones:

How to select the data? 1-30, 40-100

dataframe.iloc[0:30]
dataframe.iloc[30:100]

How to replace NaN?

dataframe.fillna('dog')
Florian Fasmeyer
  • 795
  • 5
  • 18
1

You can use fillna with a subset of your dataset (df):

df.loc[1:30, :].fillna('dog', inplace=True)
df.loc[40:100, :].fillna('cat', inplace=True)
IoaTzimas
  • 10,538
  • 2
  • 13
  • 30