I have a date sequence
from datetime import datetime
import pandas as pd
start = datetime(2018, 3, 4)
end = datetime(2018, 3, 17)
index1 = pd.date_range(start, end)
How can I extract only Monday to Friday from the sequence? Any other solution (not using datetime) will also be helpful.
You may use the paremeter freq
and set it to B
for business day frequency
index1 = pd.date_range(start, end, freq='B')
Or you can use the dedicated method pandas.bdate_range()
. You can find the other frequencies :
index1 = pd.bdate_range(start, end)
您可以将freq='B'
作为参数传递给date_range
以避免周末(仅包括工作日):
index1 = pd.date_range(start, end, freq='B')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.