fillna

fillna#

NestedFrame.fillna(value: Hashable | Mapping | Series | DataFrame | None = None, *, axis: int | Literal['index', 'columns', 'rows'] | None = None, inplace: bool = False, limit: int | None = None) NestedFrame | None[source]#

Fill NA/NaN values using the specified method for base and nested columns.

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 column. Values not in the dict/Series/DataFrame will not be filled. This value cannot be a list.

  • axis ({axes_single_arg}, default None) – 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 NestedFrame).

  • limit (int, default None) – The maximum number of entries along the entire axis where NaNs will be filled. Must be greater than 0 if not None. Currently, limit on nested columns is not supported, meaning that all Nans will be filled (if there is a value specified) regardless of the input.

Returns:

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

Return type:

NestedFrame or None

Examples

>>> import nested_pandas as npd
>>> nf = npd.NestedFrame(
...     data={"a": [np.nan, 20, np.nan], "b": [np.nan, np.nan, 30], "c": [10, np.nan, np.nan]},
...     index=[0, 1, 2]
... )
>>> nested = pd.DataFrame(
...     data={"d": [np.nan, np.nan, np.nan], "e": [np.nan, 1, np.nan]},
...     index=[0, 1, 2]
... )
>>> nf = nf.join_nested(nested, "nested")
>>> nf.fillna(0)
      a     b     c              nested
0   0.0   0.0  10.0  [{d: 0.0, e: 0.0}]
1  20.0   0.0   0.0  [{d: 0.0, e: 1.0}]
2   0.0  30.0   0.0  [{d: 0.0, e: 0.0}]