简体   繁体   English

numpy.where()没有考虑真实条件

[英]numpy.where() does not consider the true condition

When using numpy.where(), it does not consider the True condition. 使用numpy.where()时,它不会考虑True条件。 Here the time is like "165-12:40:45" and m_gear is of type int64 . 这里的时间就像“ 165-12:40:45”,而m_gear的类型是int64。 Thanks for the tip. 谢谢你的提示。

time | 时间| m_gear m_gear

165-12:40:46 | 165-12:40:46 | 0 0
165-12:40:47 | 165-12:40:47 | 1 1个
165-12:40:48 | 165-12:40:48 | 0 0
165-12:40:49 | 165-12:40:49 | 1 1个

the expected output is 预期的输出是

timeTake 时间取

165-12:40:45 165-12:40:45
165-12:40:45 165-12:40:45
165-12:40:48 165-12:40:48
165-12:40:45 165-12:40:45

df_ts['timeTake'] = np.where(((df_ts['m_gear']==0) & (df_ts.m_gear.shift()== 1)), df_ts['time'],pd.to_datetime('165-12:40:45', format='%j-%H:%M:%S') )

I'm not sure if i've caught your drift, but aren't you looking for (SettingWithCopyWarning fixed) 我不确定我是否赶上了您的进度,但您不是要寻找(SettingWithCopyWarning已修复)

df_ts['timeTake'] = df_ts['time']
df_ts.loc[(df_ts['m_gear']!=0) | (df_ts.m_gear.shift()!= 1), 'timeTake'] ='165-12:40:45'

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

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