Desired way
In order to convert two columns with year and week of year into date I would expect to do something like:
df['formatted_date'] = df.year*100+df.weekofyear
df['date'] = pd.to_datetime(df['formatted_date'], format='%Y%w')
However, it does not work, giving ValueError:
ValueError: unconverted data remains: 01
Workaround
The workaround, I have found is converting week of year into a day of year and working with year-dayofyear %Y%j
format:
df['formatted_date'] = df.year*1000+df.weekofyear*7-6
df['date'] = pd.to_datetime(df['formatted_date'], format='%Y%j')
The first line becomes ugly, but this works fine. Week of year is in the range (00,53). Any ideas, why is the elegant way not working?