Return the Modified DataFrame ( if inplace=True ).
Value to be replaced. Can be 0. We can use method to replace NaN data also
How to use the fill, values are backfill, ffill, pad
0 or 1 or Column, the axis to be used for replacement
Boolean , along with method if value is True then original ( source ) dataframe is replaced after applying fillna()
Number , along with method this is the maximum number of replacements allowed.
what to downcast if possible
We will use options with different valeus to tell how to fill the NaN data. method='backfill' , method='ffill', method='pad' Each column we will apply different methods to replace the data. Check this code and output below it.
For ENGLISH column we have used method='backfill', so the value at row 5 ( value = 30 ) is used at row 4 to replace NaN value.
For NAME column we have used method='bfill' value at 4th row is used to fill value at 3rd row.
For ID column we have used method='ffill' , here value at 1st row is used to fill value at 2nd row.
Note that the last value of NAME column and first value of MATH column is not replaced. ( Why ? )
For MATH column we have used method='pad' , it is same as ffill and as there is no value before it and for NAME column this the last row and there is no data after 5th row ( we used bfill ) , these two data are not changed.
Using axis=1 we can fill the data in row. We will use method='backfill'