我正在处理一个数据帧,我想在列上删除一些具有多个特定字符串值的行。 例如,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
等于hotel、Restaurant和estate的行,以形成如下df:
ID type price
vc947 bar $2314
bc521 bar $2191
kc818 school $91456
如何使用drop
函数获得结果
您可以使用^{} 方法获取
type
等于'hotel'
、'Restaurant'
或'estate'
的行。然后可以使用~
反转布尔过滤器或者,如果要使用^{} 方法,可以执行以下操作:
尽管出于性能原因,前者速度更快
相关问题 更多 >
编程相关推荐