【问题标题】:How to delete a row if string matches如果字符串匹配,如何删除一行
【发布时间】:2019-12-17 10:09:45
【问题描述】:

我有一个包含“@@@”系列的 DataFrame。我想删除包含此模式的行。

我写了这样的匹配代码:

df[df['employee'].str.match('@', na = False)]

如果找到匹配项,如何删除该行?

【问题讨论】:

标签: python pandas


【解决方案1】:

使用pandas.DataFrame.drop:

df = df.drop(df[df['employee'].str.match('@',na=False)].index)    

【讨论】:

    【解决方案2】:

    据我了解,您想删除employee 列中用@@@ 填充的行。如果正确,请尝试:

    df = df.loc[df["employee"] != "@@@"]
    

    【讨论】:

      猜你喜欢
      • 2022-10-15
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      相关资源
      最近更新 更多