Issue
I would like to extract a week number from data in a pandas dataframe.
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)
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.
Thanks in advance
Solution
Just access the week attribute of Series.dt.isocalendar():
Example:
In [286]:
df['Date'].dt.isocalendar().week
Out[286]:
0 25
dtype: int64
In [287]:
df['Week_Number'] = df['Date'].dt.isocalendar().week
df
Out[287]:
Date Week_Number
0 2015-06-17 25
Answered By - EdChum
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.