CoderAna
CoderAna

Reputation: 1

How can I convert YYYY-WNN to YYYY-MM-DD format where WNN is week number?

I have a dataset with date format YYY-WNN and I would to convert it to standard date format. I have tried

df_vaccine["Date"] = datetime.datetime.strptime(df_vaccine["YearWeekISO"] + '-1', "%Y-W%W-%w") 

however I am getting this error: TypeError: strptime() argument 1 must be str, not Series.

What can I do?

Thank you in advance.

Upvotes: 0

Views: 216

Answers (1)

sushanth
sushanth

Reputation: 8302

You should instead try using, pd.to_datetime

import pandas as pd

pd.to_datetime(df['YearWeekISO'], format="%Y-%W-%w").dt.strftime("%d/%m/%Y")

Upvotes: 2

Related Questions