import pandas as pd
df = pd.read_csv('aapl.csv', parse_dates=['Date'], index_col = "Date")
df.head()
Open | High | Low | Close | Volume | Adj Close | |
---|---|---|---|---|---|---|
Date | ||||||
2008-10-14 | 116.26 | 116.40 | 103.14 | 104.08 | 70749800 | 104.08 |
2008-10-13 | 104.55 | 110.53 | 101.02 | 110.26 | 54967000 | 110.26 |
2008-10-10 | 85.70 | 100.00 | 85.00 | 96.80 | 79260700 | 96.80 |
2008-10-09 | 93.35 | 95.80 | 86.60 | 88.74 | 57763700 | 88.74 |
2008-10-08 | 85.91 | 96.33 | 85.68 | 89.79 | 78847900 | 89.79 |
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay
us_business = CustomBusinessDay(calendar = USFederalHolidayCalendar())
rng = pd.date_range('2001-07-01', '2001-07-10', freq = us_business)
rng
DatetimeIndex(['2001-07-02', '2001-07-03', '2001-07-05', '2001-07-06', '2001-07-09', '2001-07-10'], dtype='datetime64[ns]', freq='C')
df[df.index.isin(rng)]
Open | High | Low | Close | Volume | Adj Close | |
---|---|---|---|---|---|---|
Date | ||||||
2001-07-10 | 22.95 | 23.07 | 20.84 | 21.14 | 14116800 | 10.57 |
2001-07-09 | 22.09 | 23.00 | 21.68 | 22.70 | 12052400 | 11.35 |
2001-07-06 | 22.76 | 22.96 | 21.72 | 22.03 | 10818600 | 11.02 |
2001-07-05 | 23.60 | 23.77 | 23.01 | 23.19 | 5439000 | 11.60 |
2001-07-03 | 23.51 | 24.18 | 23.50 | 23.84 | 4019400 | 11.92 |
2001-07-02 | 23.64 | 24.23 | 23.14 | 23.90 | 8216000 | 11.95 |
from pandas.tseries.holiday import AbstractHolidayCalendar, Holiday
class myHoliday(AbstractHolidayCalendar):
rules = [
Holiday('My Holiday', month = 7, day = 2)
]
my_business = CustomBusinessDay(calendar = myHoliday())
rng = pd.date_range('2023-07-01', '2023-07-10', freq = my_business)
rng
DatetimeIndex(['2023-07-03', '2023-07-04', '2023-07-05', '2023-07-06', '2023-07-07', '2023-07-10'], dtype='datetime64[ns]', freq='C')
my_business = CustomBusinessDay(weekmask = 'Sun Mon Tue Wed Thu')
rng = pd.date_range('2023-07-01', '2023-07-10', freq = my_business)
rng
DatetimeIndex(['2023-07-02', '2023-07-03', '2023-07-04', '2023-07-05', '2023-07-06', '2023-07-09', '2023-07-10'], dtype='datetime64[ns]', freq='C')