df_train[catcols] = df_train[catcols].fillna("NANO")
df_test[catcols[:-2]] = df_test[catcols[:-2]].fillna("NANO")
Asked
Active
Viewed 30 times
0

David Erickson
- 16,433
- 2
- 19
- 35

Derilxavier
- 3
- 1
-
2All `NaN` values in the selected columns willbe replaced with `NANO`. Does this answer your question? [How to replace NaN values by Zeroes in a column of a Pandas Dataframe?](https://stackoverflow.com/questions/13295735/how-to-replace-nan-values-by-zeroes-in-a-column-of-a-pandas-dataframe) – David Erickson Aug 06 '20 at 06:47
-
yeah understood DavidErickson – Derilxavier Aug 06 '20 at 07:06
1 Answers
0
fillna is a method in pandas series and dataframe. It replaces NA/NAN values in a dataframe.
Syntax :
df.fillna(value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs)
In this case
df_train[catcols] = df_train[catcols].fillna("NANO")
df_test[catcols[:-2]] = df_test[catcols[:-2]].fillna("NANO")
'NANO' string is replaces where a NONE value is found in the dataframe.
For example:
if your dataframe df is :
Index Name
1 Jacob
2 Andrew
3 NONE
4 NONE
5 Steve
df['Name'].fillna('Aagam')
Index Name
1 Jacob
2 Andrew
3 Aagam
4 Aagam
5 Steve
to learn more visit Pandas.dataframe.fillna

Aagam Sheth
- 685
- 7
- 15