user1315789
user1315789

Reputation: 3659

Getting list of dates (excluding weekends)

I am using python v3.6. I would like to get a list of dates that exclude weekends.

Here is what I have on hand;

import pandas as pd
datelist = pd.bdate_range(pd.datetime.today(), periods=10).tolist()

What the above code does is to return a list of dates starting from today to next 10 days.

How do I conveniently specify the starting date in the format dd/mm/yyyy to get this range? I would like to be able to do something like this;

datelist = pd.bdate_range(function_format_date("01/10/2017"), periods=10).tolist()

Upvotes: 0

Views: 640

Answers (1)

Zero
Zero

Reputation: 77027

You could do

pd.bdate_range('21/12/2017', periods=10).tolist()

Or, be more specific with pd.to_datetime(.., format=)

pd.bdate_range(pd.to_datetime('21/12/2017', format='%d/%m/%Y'), periods=10).tolist()

Upvotes: 2

Related Questions