简体   繁体   English

使用np.where时类型比较无效?

[英]invalid type comparison when using np.where?

Here is my code: 这是我的代码:

 Depth['timing']=np.where((Depth['time_entry']== 'later' )| (Depth['offer_status']=='market'), Depth['time_status_change'],Depth['time_entry'])
    Depth2['timing']=np.where((Depth2['time_entry']== 'later' ) | (Depth2['offer_status']=='market'), Depth2['time_status_change'],Depth2['time_entry'])

Update: I solved it anyways, but used some stupid loop which is not very good for performance. 更新:无论如何我都解决了,但是使用了一些愚蠢的循环,这对性能不是很好。

What I got is: invalid type comparison . 我得到的是: invalid type comparison What can I do to fix it? 我该如何解决? Depth['time_entry'] is a column with either a number or 'later' , so maybe that is the issue? Depth['time_entry']是一列包含number'later' ,所以可能是问题所在吗?

Try with converting Depth['time_entry'] in to string first and then validating against 'later' . 尝试Depth['time_entry']转换为字符串,然后根据'later'进行验证。

See this: datetime to string with series in python pandas . 参见: datetime到python pandas中带有系列的字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM