【问题标题】:Within a Pandas dataset, how do I keep only the rows that have a minimum of 4 values, deleting the rest在 Pandas 数据集中,我如何只保留至少有 4 个值的行,删除其余的行
【发布时间】:2021-05-18 20:40:50
【问题描述】:

我正在使用 pandas 数据集,需要删除值为 3 或更小的行。因此,如果有 12 列并且只有 9 列填充了需要删除该行的信息。

如果这让我感到困惑,请告诉我,我会用另一种方式解释。

感谢好心人

编辑

这是我迄今为止尝试过的代码。它给出了一个语法错误。

indexnames = dataset.row[

dataset.drop(indexnames, inplace=True)

【问题讨论】:

  • So if there are 12 columns and only 9 are populated with information that row needs to be deleted是什么意思,这句话和第一个有什么关系?
  • 它解释了一行有 3 个或更少值的情况。不是最少 4 个。
  • 您想发布您目前拥有的代码,或许还有一个示例数据框,以便我们了解您的尝试。

标签: pandas jupyter-notebook


【解决方案1】:

试试这个:

New_df= Base_df.iloc[Base_df[Base_df.isnull().sum(axis=1)>3].index]
New_df

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 2019-04-28
    相关资源
    最近更新 更多