本文整理汇总了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))
示例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))
示例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))
示例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
示例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)
示例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