将大 pandas 日期转换为星期数 [英] converting a pandas date to week number
本文介绍了将大 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 日期转换为星期数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文