【发布时间】:2021-10-10 04:45:43
【问题描述】:
我正在处理一个数据框,我想在列上删除一些具有多个特定字符串值的行。 比如df是这样的:
ID type price
da499 hotel $41946
fa987 hotel $251
gh552 Restaurant $764
vc947 bar $2314
bc521 bar $2191
fv231 Restaurant $4985
df987 estate $654
bv231 estate $231
kc818 school $91456
我想删除 type 等于酒店、餐厅和庄园的行,形成这样的 df:
ID type price
vc947 bar $2314
bc521 bar $2191
kc818 school $91456
如何使用drop 函数获取结果?
【问题讨论】:
-
df[~df['type'].isin(['hotel','Restaurant','estate'])]? -
这能回答你的问题吗? stackoverflow.com/questions/52456874/…
标签: python pandas dataframe filter conditional-statements