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.
axis: {0 or ‘index’} for Series, {0 or ‘index’, 1 or ‘columns’} for DataFrame
Axis along which to fill missing values. For Series this parameter is unused and defaults to 0.
inplace: bool, default False
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).
limit: int, default None
This is the maximum number of entries along the entire axis where NaNs will be filled. Must be greater than 0 if not None.
Returns:
Series/DataFrame
Object with missing values filled.
See also:
ffill
Fill values by propagating the last valid observation to next valid.
bfill
Fill values by using the next valid observation to fill the gap.
interpolate
Fill NaN values using interpolation.
reindex
Conform object to new index.
asfreq
Convert TimeSeries to specified frequency.
Notes:
For non-object dtype, value=None will use the NA value of the dtype. See more details in the Filling missing data section.
Examples:
>>> df = pd.DataFrame(... [... [np.nan, 2, np.nan, 0],... [3, 4, np.nan, 1],... [np.nan, np.nan, np.nan, np.nan],... [np.nan, 3, np.nan, 4],... ],... columns=list("ABCD"),... )>>> df A B C D0 NaN 2.0 NaN 0.01 3.0 4.0 NaN 1.02 NaN NaN NaN NaN3 NaN 3.0 NaN 4.0
Replace all NaN elements with 0s.
>>> df.fillna(0) A B C D0 0.0 2.0 0.0 0.01 3.0 4.0 0.0 1.02 0.0 0.0 0.0 0.03 0.0 3.0 0.0 4.0
Replace all NaN elements in column ‘A’, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively.