将大 pandas 日期转换为星期数

编程入门 行业动态 更新时间:2024-10-26 22:29:39
本文介绍了将大 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 日期转换为星期数

本文发布于:2023-10-28 19:58:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537627.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   星期   日期   pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!