Skip to content
Advertisement

Week number not matching with datetime index strftime week number in pandas

I have the following code which converts index to week number as well as another column is added with week number:

JavaScript

As you can see there are instances where week 11 is being shown in the index column using df.index.strftime('%U') when the week number is showing as 12 using df.index.isocalendar().week Why are there week number different in index column as compare to column week ?


Edit

With this:

JavaScript

I have dates

JavaScript

Advertisement

Answer

data

JavaScript

Check documentation

stftime, Sunday as the first day of the week

ISO weeks start on a Monday and end on a Sunday

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement