【发布时间】:2020-02-10 07:50:34
【问题描述】:
我有两列 startDate 和 endDate 我需要计算这些日期之间从 0 到 23 的小时数 例如,开始日期是 2000-12-05 10:00:00,结束日期是 2001-01-15 15:00:00 我需要计算在 python 中这两个日期之间从 0 到 23 小时发生了多少次
我计算了日期之间的差异,并从差异中计算出小时数。 之后我计划从 startDate 到 startDateHour * hours 提取开始时间以获得 endHour 并遍历字典以增加计数,但是还有其他方法可以做到这一点吗?
df['diff'] = df['endDate'] - df['startDate']
df['hours']= df['diff'] / np.timedelta64(1, 'h')
【问题讨论】:
标签: python pandas numpy dataframe