[英]How to calculate the time (in seconds) difference between two DateTime columns using pandas?
pandas DataFrame (df3) 包含兩列包含 timedelta64[ns],如圖所示。 您如何計算它們在新列中的差異時間(以秒為單位)?
[In][1] df3.head()
Out[1]
新的 df3 應該是這樣的:
我如何獲得總秒數的差異?
我們可以使用total_seconds
(df.dropoff_datetime-df.pickup_datetime).dt.total_seconds()
Out[514]:
0 1327.0
1 2040.0
2 1680.0
3 1975.0
4 3083.0
dtype: float64
df['diff']= (df.dropoff_datetime-df.pickup_datetime).dt.total_seconds()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.