【问题标题】:drop an element from a data frame (with error item not exist) [duplicate]从数据框中删除一个元素(错误项不存在)[重复]
【发布时间】:2020-08-22 19:24:38
【问题描述】:

我正在使用df=df.drop(index='historical book') 删除所有包含historical book 的行。

第一行是标题

id           name book              subject                       amount
1            name1                  historical book               6
2            name2                  literature book               9
3            name3                  historical book               4

我收到一个错误,它是 not found in axis。你知道为什么吗?

谢谢!

【问题讨论】:

  • 使用:df[df['subject'] != 'historical book']

标签: python pandas numpy jupyter-notebook data-visualization


【解决方案1】:

这样做:

print(df[~df['subject'].str.contains('historical book')])

   id name book          subject  amount
1   2     name2  literature book       9

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 2016-01-07
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    相关资源
    最近更新 更多