如何计算两个pandas列之间的时差

2024-04-24 00:15:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我的df看起来像

    start               stop
0   2015-11-04 10:12:00 2015-11-06 06:38:00
1   2015-11-04 10:23:00 2015-11-05 08:30:00
2   2015-11-04 14:01:00 2015-11-17 10:34:00
4   2015-11-19 01:43:00 2015-12-21 09:04:00

print(time_df.dtypes)

start       datetime64[ns]
stop        datetime64[ns]

数据类型:对象

我想找出停止和开始之间的时间差。

我试过了,pd.Timedelta(df_time['stop']-df_time['start']) 但它给出了TypeError: data type "datetime" not understood

df_time['stop']-df_time['start']也会给出相同的错误。

我的预期产量

 2D,?H
 1D,?H
 ...
 ...

Tags: 对象dfdatatimestarttimedeltapd数据类型