从数据框中删除行,其中内容可以是字符串的选择

时间:2018-12-07 20:58:34

标签: python pandas

所以我可以做类似的事情:

data = df[ df['Proposal'] != 'C000' ]

删除所有带有字符串C000的投标,但是我该怎么做:

data = df[ df['Proposal'] not in ['C000','C0001' ]

删除所有与C000或C0001相匹配的投标(等,等等)

2 个答案:

答案 0 :(得分:1)

您可以尝试一下,

TypeError: reduction operation 'argmin' not allowed for this dtype

或者选择所需的内容,

df = df.drop(df[df['Proposal'].isin(['C000','C0001'])].index)

答案 1 :(得分:0)

import numpy as np
data = df.loc[np.logical_not(df['Proposal'].isin({'C000','C0001'})), :]
# or
data = df.loc[              ~df['Proposal'].isin({'C000','C0001'}) , :]