Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convet W(Number)-Y(NUMBER) to date in Python

Using Python:

How do we convert a series of dates W(Number)-Y(NUMBER) in the following format ‘YYYY-MM-DD’

Example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

W01-16
W02-16
W03-16
...

To:

2016-01-04
2016-01-11
2016-01-18
...

>Solution :

Adapated from Get date from week number

  • %w for day of week, giving 1 to be monday
  • %W for week of year
  • %y for year on 2 digits
from datetime import datetime

d = "W01-16"
print(datetime.strptime('1-' + d, "%w-W%W-%y"))  # 2016-01-04 00:00:00

from datetime import datetime
from pandas import Series

s = Series(["W01-16", "W02-16", "W03-16"])
s = s.apply(lambda d: datetime.strptime('1-' + d, "%w-W%W-%y"))
print(s)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading