pandas 1.4.2

ParametersReturnsBackRef
fillna(self, value: 'object | ArrayLike | None' = None, method: 'FillnaOptions | None' = None, axis=None, inplace=False, limit=None, downcast=None) -> 'Series | None'

Parameters

value : scalar, dict, Series, or DataFrame

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.

method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None

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.

axis : {0 or 'index'}

Axis along which to fill missing values.

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

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.

downcast : dict, default is None

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).

Returns

Series or None

Object with missing values filled or None if inplace=True .

Fill NA/NaN values using the specified method.

See Also

asfreq

Convert TimeSeries to specified frequency.

interpolate

Fill NaN values using interpolation.

reindex

Conform object to new index.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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 D 0 NaN 2.0 NaN 0.0 1 3.0 4.0 NaN 1.0 2 NaN NaN NaN NaN 3 NaN 3.0 NaN 4.0

Replace all NaN elements with 0s.

This example is valid syntax, but we were not able to check execution
>>> df.fillna(0)
     A    B    C    D
0  0.0  2.0  0.0  0.0
1  3.0  4.0  0.0  1.0
2  0.0  0.0  0.0  0.0
3  0.0  3.0  0.0  4.0

We can also propagate non-null values forward or backward.

This example is valid syntax, but we were not able to check execution
>>> df.fillna(method="ffill")
     A    B   C    D
0  NaN  2.0 NaN  0.0
1  3.0  4.0 NaN  1.0
2  3.0  4.0 NaN  1.0
3  3.0  3.0 NaN  4.0

Replace all NaN elements in column 'A', 'B', 'C', and 'D', with 0, 1, 2, and 3 respectively.

This example is valid syntax, but we were not able to check execution
>>> values = {"A": 0, "B": 1, "C": 2, "D": 3}
... df.fillna(value=values) A B C D 0 0.0 2.0 2.0 0.0 1 3.0 4.0 2.0 1.0 2 0.0 1.0 2.0 3.0 3 0.0 3.0 2.0 4.0

Only replace the first NaN element.

This example is valid syntax, but we were not able to check execution
>>> df.fillna(value=values, limit=1)
     A    B    C    D
0  0.0  2.0  2.0  0.0
1  3.0  4.0  NaN  1.0
2  NaN  1.0  NaN  3.0
3  NaN  3.0  NaN  4.0

When filling using a DataFrame, replacement happens along the same column names and same indices

This example is valid syntax, but we were not able to check execution
>>> df2 = pd.DataFrame(np.zeros((4, 4)), columns=list("ABCE"))
... df.fillna(df2) A B C D 0 0.0 2.0 0.0 0.0 1 3.0 4.0 0.0 1.0 2 0.0 0.0 0.0 NaN 3 0.0 3.0 0.0 4.0

Note that column D is not affected since it is not present in df2.

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.groupby.groupby.GroupBy.backfill pandas.core.series.Series.dropna pandas.core.groupby.groupby.GroupBy.pad pandas.core.groupby.groupby.GroupBy.ffill pandas.core.indexes.base.Index.fillna pandas.core.groupby.groupby.GroupBy.bfill pandas.core.series.Series.replace

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/series.py#4897
type: <class 'function'>
Commit: