Pandas DataFrame: fillna() function

DataFrame-fillna() function

The fillna() function is used to fill NA/NaN values using the specified method.


DataFrame.fillna(self, value=None, method=None, axis=None, inplace=False, limit=None, downcast=None, **kwargs)


Name Description Type/Default Value Required / Optional
value              Value to use to fill holes (e.g. 0), alternately a dict/Series/DataFrame of values specifying which value to use for each index (for a Series) or column (for a DataFrame). Values not in the dict/Series/DataFrame will not be filled. This value cannot be a list. scalar, dict, Series, or DataFrame Required
method   Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use next valid observation to fill gap. {‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}
Default Value: None
axis   Axis along which to fill missing values. {0 or ‘index’, 1 or ‘columns’} Optional
inplace   If True, fill in-place. Note: this will modify any other views on this object (e.g., a no-copy slice for a column in a DataFrame). bool
Default Value: False
limit   If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled. Must be greater than 0 if not None. int
Default Value: None
downcast  A dict of item->dtype of what to downcast if possible, or the string ‘infer’ which will try to downcast to an appropriate equal type (e.g. float64 to int64 if possible). dict
Default Value: None

Returns: DataFrame
Object with missing values filled.


Download the above Notebook from here.

Previous: DataFrame-dropna() function
Next: DataFrame-replace() function