How To Calculate The Time (in Seconds) Difference Between Two Datetime Columns Using Pandas?
A pandas DataFrame (df3) has contained two columns contain timedelta64[ns] as shown. How can you calculate the difference time of them in seconds in a new column? [In][1] df3.head(
Solution 1:
We can use 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()
Post a Comment for "How To Calculate The Time (in Seconds) Difference Between Two Datetime Columns Using Pandas?"