簡體   English   中英

numpy.where()沒有考慮真實條件

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

使用numpy.where()時,它不會考慮True條件。 這里的時間就像“ 165-12:40:45”,而m_gear的類型是int64。 謝謝你的提示。

時間| m_gear

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

預期的輸出是

時間取

165-12:40:45
165-12:40:45
165-12:40:48
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') )

我不確定我是否趕上了您的進度,但您不是要尋找(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