过滤数据框时出错(TypeError:无效的类型比较)

时间:2018-12-20 18:36:51

标签: pandas

我正在尝试根据列过滤出一个数据框,但出现错误TypeError: invalid type comparison

下面是我的数据框的视图:

id,name,start_date,new_customer
101,customer_1,2018-12-01,True
102,customer_2,2018-11-21,False
103,customer_3,2018-12-11,True
104,customer_4,2018-11-30,False

尝试执行时出现错误

df = df['new_customer']=='True'

更新

df.dtypes


id - object
name - object
start_date - datetime64[ns]
new_customer - bool

1 个答案:

答案 0 :(得分:1)

使用True,不要加引号

df = df['new_customer'] == True
相关问题