python_计算两个日期之间的时间差

python_计算两个日期之间的时间差

# 计算两个日期之间的时间差
import pandas as pd
​
# 
dataframe = pd.DataFrame()# 创建两个 datetime 特征
dataframe['Arrived'] = [pd.Timestamp('01-01-2017'), pd.Timestamp('01-04-2017')]
dataframe['Left'] = [pd.Timestamp('01-01-2017'), pd.Timestamp('01-06-2017')]
dataframe['Arrived']
dataframe['Left']
# 计算两个时间差
dataframe['Left'] - dataframe['Arrived']
0   0 days
1   2 days
dtype: timedelta64[ns]
  移出days
# 计算两个特征之间的时间间隔  移出days
pd.Series(delta.days for delta in (dataframe['Left'] - dataframe['Arrived']))
0    0
1    2
dtype: int64

你可能感兴趣的:(Python,pandas)