pandas.Series.dropna#

Series.dropna(*, axis=0, inplace=False, how=None, ignore_index=False)[源代码]#

返回一个移除了缺失值的新 Series。

有关哪些值被视为缺失值以及如何处理缺失数据,请参阅 User Guide

Parameters:
axis{0 或 ‘index’}

未使用。参数是与 DataFrame 兼容性所必需的。

inplacebool,默认 False

如果为 True,则就地执行操作并返回 None。

howbool, default False

未使用。为保持兼容性而保留。

ignore_index : bool, 默认 Falsebool, 默认

如果为 True,则结果轴将标记为 0, 1, …, n - 1。

在 2.0.0 版本加入.

Returns:
Series 或 None

从中删除 NA 条目的 Series,如果 inplace=True 则返回 None。

参见

Series.isna

指示缺失值。

Series.notna

指示存在的(非缺失)值。

Series.fillna

替换缺失值。

DataFrame.dropna

删除包含 NA 值的行或列。

Index.dropna

删除缺失的索引。

Examples

>>> ser = pd.Series([1., 2., np.nan])
>>> ser
0    1.0
1    2.0
2    NaN
dtype: float64

删除 Series 中的 NA 值。

>>> ser.dropna()
0    1.0
1    2.0
dtype: float64

空字符串不被视为 NA 值。None 被视为 NA 值。

>>> ser = pd.Series([np.nan, 2, pd.NaT, '', None, 'I stay'])
>>> ser
0       NaN
1         2
2       NaT
3
4      None
5    I stay
dtype: object
>>> ser.dropna()
1         2
3
5    I stay
dtype: object