我首先将日期和时间(开始时间和完成时间)转换为DateTime对象。以前的格式如下:6/28/2013 14:37
df['started_at'] = pd.to_datetime(df['open_date'])
df['started_at'].head()
df['completed_at'] = pd.to_datetime(df['closed_date'])
df['completed_at'].head()
我将开放日期重命名为started_at,将结束日期重命名为completed_at
df['started_at'].head()
2013-06-26 11:57:00
2013-06-26 11:58:00
2013-06-26 11:59:00
2013-06-26 12:02:00
2013-06-26 12:04:00
Name: started_at, dtype: datetime64[ns]
df['completed_at'].head()
2013-06-28 14:37:00
2013-06-27 14:37:00
2013-07-03 14:39:00
2013-07-01 14:47:00
2013-07-01 14:44:00
Name: completed_at, dtype: datetime64[ns]
现在,我想计算开始时间和完成时间之间的天数。