当前位置: 首页>>代码示例>>Python>>正文


Python holiday.USFederalHolidayCalendar方法代码示例

本文整理汇总了Python中pandas.tseries.holiday.USFederalHolidayCalendar方法的典型用法代码示例。如果您正苦于以下问题:Python holiday.USFederalHolidayCalendar方法的具体用法?Python holiday.USFederalHolidayCalendar怎么用?Python holiday.USFederalHolidayCalendar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.tseries.holiday的用法示例。


在下文中一共展示了holiday.USFederalHolidayCalendar方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_calendar

# 需要导入模块: from pandas.tseries import holiday [as 别名]
# 或者: from pandas.tseries.holiday import USFederalHolidayCalendar [as 别名]
def test_calendar(self):
        calendar = USFederalHolidayCalendar()
        dt = datetime(2014, 1, 17)
        assert_offset_equal(CDay(calendar=calendar), dt, datetime(2014, 1, 21)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_offsets.py

示例2: test_datetimeindex

# 需要导入模块: from pandas.tseries import holiday [as 别名]
# 或者: from pandas.tseries.holiday import USFederalHolidayCalendar [as 别名]
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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_offsets.py

示例3: test_datetimeindex

# 需要导入模块: from pandas.tseries import holiday [as 别名]
# 或者: from pandas.tseries.holiday import USFederalHolidayCalendar [as 别名]
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)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:test_offsets.py

示例4: judgeOpenDaysInRange

# 需要导入模块: from pandas.tseries import holiday [as 别名]
# 或者: from pandas.tseries.holiday import USFederalHolidayCalendar [as 别名]
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 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:11,代码来源:Fetch_Data_Stock_US_Weekly.py

示例5: convert_month_based_data

# 需要导入模块: from pandas.tseries import holiday [as 别名]
# 或者: from pandas.tseries.holiday import USFederalHolidayCalendar [as 别名]
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) 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:9,代码来源:utils.py

示例6: load_data_with_features

# 需要导入模块: from pandas.tseries import holiday [as 别名]
# 或者: from pandas.tseries.holiday import USFederalHolidayCalendar [as 别名]
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 
开发者ID:locuslab,项目名称:e2e-model-learning,代码行数:49,代码来源:main.py


注:本文中的pandas.tseries.holiday.USFederalHolidayCalendar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。