pandas将日期转换为周数

时间:2018-03-01 13:02:29

标签: pandas

我在尝试将date转换为星期时遇到此错误 可能是日期值而非日期时间,如值?

data['DATECREATED'].dt.week

error screenshot

1 个答案:

答案 0 :(得分:2)

我认为您需要首先将列转换为datetime并分配回列:

data['DATECREATED'] = pd.to_datetime(data['DATECREATED'])
data['new'] = data['DATECREATED'].dt.strftime('%Y%V')
data['CreatedWW'] = data['DATECREATED'].dt.week