Reputation: 49
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()
Out[1]
The new df3 should be like:
how do I get difference in total seconds?
Upvotes: 2
Views: 869
Reputation: 323236
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()
Upvotes: 5