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,048
  • 4
  • 22
  • 42

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
  • 729,927
  • 78
  • 1,141
  • 1,090
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,327
  • 13
  • 18