Shi Jie Tio
Shi Jie Tio

Reputation: 2529

How to get the last work week of the last month in previous year in Python Pandas?

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?

Upvotes: 0

Views: 77

Answers (1)

BENY
BENY

Reputation: 323226

Using Timestamp and Timedelta

(pd.Timestamp.now()-pd.Timedelta('7 days')).strftime('%Y-%U')
Out[148]: '2017-52'

Upvotes: 1

Related Questions