标签: pandas
我在尝试将date转换为星期时遇到此错误 可能是日期值而非日期时间,如值?
data['DATECREATED'].dt.week
error screenshot
答案 0 :(得分:2)
我认为您需要首先将列转换为datetime并分配回列:
datetime
data['DATECREATED'] = pd.to_datetime(data['DATECREATED']) data['new'] = data['DATECREATED'].dt.strftime('%Y%V') data['CreatedWW'] = data['DATECREATED'].dt.week