3

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"?

salient
  • 2,316
  • 6
  • 28
  • 43

2 Answers2

1

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.

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
1

1.The behaviour is ok.

pd.to_datetime('2015-09', format='%Y-%W', dayfirst='True')

Timestamp('2015-01-01 00:00:00')

2.you can try this.

pd.to_datetime([1, 2, 3], unit='D', origin=pd.Timestamp('1960-01-01'))

DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'], type='datetime64[ns]', freq=None)
youDaily
  • 1,372
  • 13
  • 21