这是我的数据
omzet_activity_paid_count_january_devices
No Text
1 dcbjkd
2 hdgfhds
3 dsdfs
33 jhsda
40 ydgyua
我希望过滤这样的数据
omzet_activity_paid_count_january_devices
No Text
3 dsdfs
40 ydgyua
这就是我做的事情
user_internal = ['1','2','33']
omzet_activity_paid_count_january_devices = omzet_activity_paid_count_january_devices[~omzet_activity_paid_count_january_devices.No.isin(user_internal)]
上面的代码不起作用,输出仍然像我的原始数据帧,我错过了什么?
答案 0 :(得分:1)
我认为你有混合类型的问题 - 带字符串的数字。
omzet_activity_paid_count_january_devices.No.dtype
dtype('O')
omzet_activity_paid_count_january_devices.No.head().tolist()
[1, 2, 3, 33, 40]
所以将列No
转换为字符串:
user_internal = ['1','2','33']
mask = ~omzet_activity_paid_count_january_devices.No.astype(str).isin(user_internal)
omzet_activity_paid_count_january_devices = omzet_activity_paid_count_january_devices[mask]
或者将string
从列表更改为int
s:
user_internal = [1,2,33]
mask = ~omzet_activity_paid_count_january_devices.No.isin(user_internal)
omzet_activity_paid_count_january_devices = omzet_activity_paid_count_january_devices[mask]