I am trying to define a function which can fill zero in all the Nan
values for all the columns of the input dataframe.
The function takes 1 fixed argument (dataframe name) and variable number of arguments for column names in the dataframe.
I am using below code -
def makeNa(df,*colnames):
for col in colnames:
return df.fillna({col:0},inplace=True)
The function works when I pass only one column name e.g. makeNa(df_test,'USA')
-it makes all the Nan values as zero for column 'USA'
but the function doesn't work while inputting more than one column names e.g. makeNa(df_test,'USA','Japan')
--> it doesnt zero the Nan values in column 'Japan'