0

Today is 2nd of January, if using Python pandas, any ideas on how to get the previous workweek?

For example today is work week 201801, and previous week is 201752, any ways can find the previous workweek of today?

Shi Jie Tio
  • 2,479
  • 5
  • 24
  • 41

1 Answers1

1

Using Timestamp and Timedelta

(pd.Timestamp.now()-pd.Timedelta('7 days')).strftime('%Y-%U')
Out[148]: '2017-52'
BENY
  • 317,841
  • 20
  • 164
  • 234
  • hi, sorry for that, I notice this a=dt.datetime.now() currentWW=a.strftime('%Y%U') will return 201800 for me, how to make sure first week of the year is start with 01? – Shi Jie Tio Jan 02 '18 at 03:43
  • @ShiJieTio you can check here https://stackoverflow.com/questions/2600775/how-to-get-week-number-in-python – BENY Jan 02 '18 at 04:32