Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing YYYY-WW to Timestamp to datetime in pandas

Tags:

python

pandas

Trying to parse dates on the format YYYY-WW to a Timestamp but this just yields the start date of the year, like so:

In [11]: pd.to_datetime('2015-09', format='%Y-%W')
Out[11]: Timestamp('2015-01-01 00:00:00')

Is this the expected behaviour? If so, how can I yield the "first day starting"?

like image 608
salient Avatar asked Dec 17 '25 13:12

salient


1 Answers

You need specify also day of week:

print (pd.to_datetime('2015-09' + '-0', format='%Y-%W-%w'))
2015-03-08 00:00:00

print (pd.to_datetime('2015-09' + '-1', format='%Y-%W-%w'))
2015-03-02 00:00:00

print (pd.to_datetime('2015-09' + '-2', format='%Y-%W-%w'))
2015-03-03 00:00:00

More info is here.

like image 95
jezrael Avatar answered Dec 19 '25 02:12

jezrael