本文介绍了将大 pandas 日期转换为星期数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从熊猫数据框中的数据中提取一个星期数.
I would like to extract a week number from data in a pandas dataframe.
日期格式为datetime64 [ns]
The date format is datetime64[ns]
我已经对日期进行了归一化以从中删除时间
I have normalized the date to remove the time from it
df['Date'] = df['Date'].apply(pd.datetools.normalize_date)所以日期现在在数据框列中看起来像是-2015-06-17
so the date now looks like - 2015-06-17 in the data frame column
现在我想将其转换为星期数.
and now I like to convert that to a week number.
预先感谢
推荐答案只需访问 dt 星期属性:
Just access the dt week attribute:
In [286]: df['Date'].dt.week Out[286]: 0 25 dtype: int64 In [287]: df['Week_Number'] = df['Date'].dt.week df Out[287]: Date Week_Number 0 2015-06-17 25更多推荐
将大 pandas 日期转换为星期数
发布评论