pandas报错:'<' not supported between instances of 'str' and 'int'

pandas报错:'<' not supported between instances of 'str' and 'int'

记录一个bug:

series原始数据如下:

image-20200504112232338

虽然我使用命令job_yearSeries=job_yearSeries.replace(to_replace=[r'N'],value=int(-1))将那个N转换为了-1,但是我没有改变series的数据类型。因为这个值的存在,该series的原始数据类型不是int而是str,所以调用job_yearSeries_boxed=pd.qcut(job_yearSeries,7)的时候会报错。解决方法就是改变数据类型:job_yearSeries=pd.to_numeric(job_yearSeries)

原文地址:https://www.cnblogs.com/jiading/p/12825854.html