python常用函数
作者:互联网
numpy.unique
numpy.unique 函数用于去除数组中的重复元素
data['date_parsed'] = pd.to_datetime(data['Date'], infer_datetime_format=True)
data['date_parsed'] = pd.to_datetime(data['Date'], format = "%m/%d/%Y", errors = 'coerce')
https://blog.csdn.net/qq_46092061/article/details/118673147
df['purchase_date'] = pd.to_datetime(df['purchase_date'])
df['year'] = df['purchase_date'].dt.year
df['weekofyear'] = df['purchase_date'].dt.weekofyear
df['month'] = df['purchase_date'].dt.month
df['dayofweek'] = df['purchase_date'].dt.dayofweek
df['weekend'] = (df.purchase_date.dt.weekday >=5).astype(int)
df['hour'] = df['purchase_date'].dt.hour
关于时序量的做差等
train['elapsed_time'] = (datetime.date(2018, 2, 1) - train['first_active_month'].dt.date).dt.days
或者
df_hist_trans_group['new_hist_purchase_date_diff'] =
(df_hist_trans_group['new_hist_purchase_date_max'] -
df_hist_trans_group['new_hist_purchase_date_min']).dt.days 可以转化类型 为整型
标签:purchase,常用,函数,python,datetime,hist,df,date,dt 来源: https://www.cnblogs.com/faithtwo/p/15440135.html