maxframe.dataframe.DataFrame.dropna#
- DataFrame.dropna(axis=0, how=<no_default>, thresh=<no_default>, subset=None, inplace=False, ignore_index=False)#
移除缺失值。
参见 用户指南 了解更多关于哪些值被视为缺失以及如何处理缺失数据的信息。
- 参数:
axis ({0 or 'index', 1 or 'columns'}, default 0) -- 确定是否移除包含缺失值的行或列。 * 0 或 'index':删除包含缺失值的行。 * 1 或 'columns':删除包含缺失值的列。
how ({'any', 'all'}, default 'any') -- 确定在至少有一个 NA 或全部为 NA 时是否从 DataFrame 中删除行或列。 * 'any':如果存在任何 NA 值,则删除该行或列。 * 'all':如果所有值都是 NA,则删除该行或列。
thresh (int, optional) -- 要求有这么多非 NA 值。
subset (array-like, optional) -- 要考虑的其他轴上的标签,例如,如果您正在删除行,则这些将是需要包含的列列表。
inplace (bool, default False) -- 如果为 True,则就地执行操作并返回 None。
ignore_index (bool, default False) -- 如果为 True,则结果轴将被标记为 0, 1, …, n - 1。
- 返回:
从中删除了 NA 条目的 DataFrame。
- 返回类型:
参见
DataFrame.isna指示缺失值。
DataFrame.notna指示存在的(非缺失)值。
DataFrame.fillna替换缺失值。
Series.dropna删除缺失值。
Index.dropna删除缺失的索引。
示例
>>> import maxframe.dataframe as md >>> df = md.DataFrame({"name": ['Alfred', 'Batman', 'Catwoman'], ... "toy": [np.nan, 'Batmobile', 'Bullwhip'], ... "born": [md.NaT, md.Timestamp("1940-04-25"), ... md.NaT]}) >>> df.execute() name toy born 0 Alfred NaN NaT 1 Batman Batmobile 1940-04-25 2 Catwoman Bullwhip NaT
删除至少有一个元素缺失的行。
>>> df.dropna().execute() name toy born 1 Batman Batmobile 1940-04-25
删除所有元素都缺失的行。
>>> df.dropna(how='all').execute() name toy born 0 Alfred NaN NaT 1 Batman Batmobile 1940-04-25 2 Catwoman Bullwhip NaT
只保留至少有2个非NA值的行。
>>> df.dropna(thresh=2).execute() name toy born 1 Batman Batmobile 1940-04-25 2 Catwoman Bullwhip NaT
定义在哪些列中查找缺失值。
>>> df.dropna(subset=['name', 'born']).execute() name toy born 1 Batman Batmobile 1940-04-25
将包含有效条目的DataFrame保留在同一变量中。
>>> df.dropna(inplace=True) >>> df.execute() name toy born 1 Batman Batmobile 1940-04-25