【问题标题】:excluding rows from a pandas dataframe based on column value and not index value根据列值而不是索引值从熊猫数据框中排除行
【发布时间】:2016-03-03 07:13:50
【问题描述】:

我查看了数据框列中的唯一值 - 我拥有的 pandas。在我不想包含的列之一中有一些名称,如何从数据框中删除这些行,而不使用索引值表示法,而是说 if row value = "this" then remove

喜欢...

new = df.copy

df['some column'].drop_values('this','that','other')

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    参见indexing with isin(另请参阅boolean indexing):

    mask = df['some column'].isin(['this', 'that', 'other'])
    df[~mask]
    

    【讨论】:

    猜你喜欢
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多