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 i
Here is another possibility using strftime. strftime.org is a good resource.
df['Week_Number'] = df['Date'].dt.strftime('%U')
'%U'
represents the week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.
If you have dates from multiple years, I recommend creating a Year-Week combination
df['Year-Week'] = df['Date'].dt.strftime('%Y-%U')