Python pandas.tseries.holiday.USFederalHolidayCalendar() Examples

The following are 20 code examples of pandas.tseries.holiday.USFederalHolidayCalendar(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.tseries.holiday , or try the search function .
Example #1
Source File: test_offsets.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_datetimeindex(self):
        hcal = USFederalHolidayCalendar()
        cbmb = CBMonthBegin(calendar=hcal)
        assert (date_range(start='20120101', end='20130101',
                           freq=cbmb).tolist()[0] == datetime(2012, 1, 3)) 
Example #2
Source File: test_offsets.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_calendar(self):
        calendar = USFederalHolidayCalendar()
        dt = datetime(2014, 1, 17)
        assert_offset_equal(CDay(calendar=calendar), dt, datetime(2014, 1, 21)) 
Example #3
Source File: test_offsets.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_datetimeindex(self):
        from pandas.tseries.holiday import USFederalHolidayCalendar
        hcal = USFederalHolidayCalendar()
        freq = CBMonthEnd(calendar=hcal)

        assert (DatetimeIndex(start='20120101', end='20130101',
                              freq=freq).tolist()[0] == datetime(2012, 1, 31)) 
Example #4
Source File: Fetch_Data_Stock_US_Monthly.py    From StockRecommendSystem with MIT License 6 votes vote down vote up
def judgeOpenDaysInRange(from_date, to_date):
    cal = USFederalHolidayCalendar()
    holidays = cal.holidays(from_date, to_date)
    duedays = pd.bdate_range(from_date, to_date)
    df = pd.DataFrame()
    df['date'] = duedays
    df['holiday'] = duedays.isin(holidays)
    opendays = df[df['holiday'] == False]
    return opendays 
Example #5
Source File: utils.py    From StockRecommendSystem with MIT License 6 votes vote down vote up
def convert_month_based_data(df):
    month_index =df.index.to_period('M')
    min_day_in_month_index = pd.to_datetime(df.set_index(month_index, append=True).reset_index(level=0).groupby(level=0)['open'].min())
    custom_month_starts = CustomBusinessMonthBegin(calendar = USFederalHolidayCalendar())
    ohlc_dict = {'open':'first','high':'max','low':'min','close': 'last','volume': 'sum'}
    mthly_data = df.resample(custom_month_starts).agg(ohlc_dict)
    return mthly_data.dropna(inplace = True) 
Example #6
Source File: test_offsets.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_calendar(self):
        calendar = USFederalHolidayCalendar()
        dt = datetime(2014, 1, 17)
        assert_offset_equal(CDay(calendar=calendar), dt, datetime(2014, 1, 21)) 
Example #7
Source File: test_offsets.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_datetimeindex(self):
        from pandas.tseries.holiday import USFederalHolidayCalendar
        hcal = USFederalHolidayCalendar()
        freq = CBMonthEnd(calendar=hcal)

        assert (date_range(start='20120101', end='20130101',
                           freq=freq).tolist()[0] == datetime(2012, 1, 31)) 
Example #8
Source File: test_offsets.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_datetimeindex(self):
        hcal = USFederalHolidayCalendar()
        cbmb = CBMonthBegin(calendar=hcal)
        assert (date_range(start='20120101', end='20130101',
                           freq=cbmb).tolist()[0] == datetime(2012, 1, 3)) 
Example #9
Source File: test_offsets.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_datetimeindex(self):
        hcal = USFederalHolidayCalendar()
        cbmb = CBMonthBegin(calendar=hcal)
        assert (DatetimeIndex(start='20120101', end='20130101',
                              freq=cbmb).tolist()[0] == datetime(2012, 1, 3)) 
Example #10
Source File: test_offsets.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_calendar(self):
        calendar = USFederalHolidayCalendar()
        dt = datetime(2014, 1, 17)
        assert_offset_equal(CDay(calendar=calendar), dt, datetime(2014, 1, 21)) 
Example #11
Source File: test_offsets.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_datetimeindex(self):
        from pandas.tseries.holiday import USFederalHolidayCalendar
        hcal = USFederalHolidayCalendar()
        freq = CBMonthEnd(calendar=hcal)

        assert (DatetimeIndex(start='20120101', end='20130101',
                              freq=freq).tolist()[0] == datetime(2012, 1, 31)) 
Example #12
Source File: test_offsets.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_calendar(self):
        calendar = USFederalHolidayCalendar()
        dt = datetime(2014, 1, 17)
        assert_offset_equal(CDay(calendar=calendar), dt, datetime(2014, 1, 21)) 
Example #13
Source File: test_offsets.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_datetimeindex(self):
        hcal = USFederalHolidayCalendar()
        cbmb = CBMonthBegin(calendar=hcal)
        assert (date_range(start='20120101', end='20130101',
                           freq=cbmb).tolist()[0] == datetime(2012, 1, 3)) 
Example #14
Source File: test_offsets.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_datetimeindex(self):
        from pandas.tseries.holiday import USFederalHolidayCalendar
        hcal = USFederalHolidayCalendar()
        freq = CBMonthEnd(calendar=hcal)

        assert (date_range(start='20120101', end='20130101',
                           freq=freq).tolist()[0] == datetime(2012, 1, 31)) 
Example #15
Source File: test_offsets.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_calendar(self):
        calendar = USFederalHolidayCalendar()
        dt = datetime(2014, 1, 17)
        assert_offset_equal(CDay(calendar=calendar), dt, datetime(2014, 1, 21)) 
Example #16
Source File: Fetch_Data_Stock_US_Daily.py    From StockRecommendSystem with MIT License 5 votes vote down vote up
def judgeOpenDaysInRange(from_date, to_date):
    cal = USFederalHolidayCalendar()
    holidays = cal.holidays(from_date, to_date)
    duedays = pd.bdate_range(from_date, to_date)
    df = pd.DataFrame()
    df['date'] = duedays
    df['holiday'] = duedays.isin(holidays)
    opendays = df[df['holiday'] == False]
    return opendays 
Example #17
Source File: Fetch_Data_Stock_US_Weekly.py    From StockRecommendSystem with MIT License 5 votes vote down vote up
def judgeOpenDaysInRange(from_date, to_date):
    cal = USFederalHolidayCalendar()
    holidays = cal.holidays(from_date, to_date)
    duedays = pd.bdate_range(from_date, to_date)
    df = pd.DataFrame()
    df['date'] = duedays
    df['holiday'] = duedays.isin(holidays)
    opendays = df[df['holiday'] == False]
    return opendays 
Example #18
Source File: test_offsets.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_datetimeindex(self):
        hcal = USFederalHolidayCalendar()
        cbmb = CBMonthBegin(calendar=hcal)
        assert (DatetimeIndex(start='20120101', end='20130101',
                              freq=cbmb).tolist()[0] == datetime(2012, 1, 3)) 
Example #19
Source File: main.py    From e2e-model-learning with Apache License 2.0 5 votes vote down vote up
def load_data_with_features(filename):
    tz = pytz.timezone("America/New_York")
    df = pd.read_csv(filename, sep=" ", header=None, usecols=[1,2,3], 
        names=["time","load","temp"])
    df["time"] = df["time"].apply(dt.fromtimestamp, tz=tz)
    df["date"] = df["time"].apply(lambda x: x.date())
    df["hour"] = df["time"].apply(lambda x: x.hour)
    df.drop_duplicates("time", inplace=True)

    # Create one-day tables and interpolate missing entries
    df_load = df.pivot(index="date", columns="hour", values="load")
    df_temp = df.pivot(index="date", columns="hour", values="temp")
    df_load = df_load.transpose().fillna(method="backfill").transpose()
    df_load = df_load.transpose().fillna(method="ffill").transpose()
    df_temp = df_temp.transpose().fillna(method="backfill").transpose()
    df_temp = df_temp.transpose().fillna(method="ffill").transpose()

    holidays = USFederalHolidayCalendar().holidays(
        start='2008-01-01', end='2014-12-31').to_pydatetime()
    holiday_dates = set([h.date() for h in holidays])

    s = df_load.reset_index()["date"]
    data={"weekend": s.apply(lambda x: x.isoweekday() >= 6).values,
          "holiday": s.apply(lambda x: x in holiday_dates).values,
          "dst": s.apply(lambda x: tz.localize(
            dt.combine(x, dt.min.time())).dst().seconds > 0).values,
          "cos_doy": s.apply(lambda x: np.cos(
            float(x.timetuple().tm_yday)/365*2*np.pi)).values,
          "sin_doy": s.apply(lambda x: np.sin(
            float(x.timetuple().tm_yday)/365*2*np.pi)).values}
    df_feat = pd.DataFrame(data=data, index=df_load.index)

    # Construct features and normalize (all but intercept)
    X = np.hstack([df_load.iloc[:-1].values,        # past load
                    df_temp.iloc[:-1].values,       # past temp
                    df_temp.iloc[:-1].values**2,    # past temp^2
                    df_temp.iloc[1:].values,        # future temp
                    df_temp.iloc[1:].values**2,     # future temp^2
                    df_temp.iloc[1:].values**3,     # future temp^3
                    df_feat.iloc[1:].values,        
                    np.ones((len(df_feat)-1, 1))]).astype(np.float64)
    X[:,:-1] = \
        (X[:,:-1] - np.mean(X[:,:-1], axis=0)) / np.std(X[:,:-1], axis=0)

    Y = df_load.iloc[1:].values

    return X, Y 
Example #20
Source File: test_offsets.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_datetimeindex(self):
        from pandas.tseries.holiday import USFederalHolidayCalendar
        hcal = USFederalHolidayCalendar()
        freq = CBMonthEnd(calendar=hcal)

        assert (date_range(start='20120101', end='20130101',
                           freq=freq).tolist()[0] == datetime(2012, 1, 31))