计算两列之间的Pandas DataFrame时间差异(以小时和分钟为单位)
我在数据框中有两列fromdate和todate。 import pandas as pd data = {'todate': [pd.Timestamp('2014-01-24 13:03:12.050000'), pd.Timestamp('2014-01-27 11:57:18.240000'), pd.Timestamp('2014-01-23 10:07:47.660000')], 'fromdate': [pd.Timestamp('2014-01-26 23:41:21.870000'), pd.Timestamp('2014-01-27 15:38:22.540000'), pd.Timestamp('2014-01-23 18:50:41.420000')]} df = pd.DataFrame(data) 我添加了一个新列,diff以使用找出两个日期之间的差异 df['diff'] = df['fromdate'] - df['todate'] 我得到了该diff列,但是days当超过24小时时,它包含。 todate fromdate diff 0 2014-01-24 13:03:12.050 2014-01-26 23:41:21.870 2 days 10:38:09.820000 1 2014-01-27 11:57:18.240 2014-01-27 15:38:22.540 0 days 03:41:04.300000 …