本文整理汇总了Python中pandas.tseries.offsets.MonthEnd方法的典型用法代码示例。如果您正苦于以下问题:Python offsets.MonthEnd方法的具体用法?Python offsets.MonthEnd怎么用?Python offsets.MonthEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.tseries.offsets
的用法示例。
在下文中一共展示了offsets.MonthEnd方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_month_range_union_tz_dateutil
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_month_range_union_tz_dateutil(self):
from pandas._libs.tslibs.timezones import dateutil_gettz
tz = dateutil_gettz('US/Eastern')
early_start = datetime(2011, 1, 1)
early_end = datetime(2011, 3, 1)
late_start = datetime(2011, 3, 1)
late_end = datetime(2011, 5, 1)
early_dr = date_range(start=early_start, end=early_end, tz=tz,
freq=MonthEnd())
late_dr = date_range(start=late_start, end=late_end, tz=tz,
freq=MonthEnd())
early_dr.union(late_dr)
示例2: test_month_range_union_tz_pytz
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_month_range_union_tz_pytz(self):
from pytz import timezone
tz = timezone('US/Eastern')
early_start = datetime(2011, 1, 1)
early_end = datetime(2011, 3, 1)
late_start = datetime(2011, 3, 1)
late_end = datetime(2011, 5, 1)
early_dr = date_range(start=early_start, end=early_end, tz=tz,
freq=MonthEnd())
late_dr = date_range(start=late_start, end=late_end, tz=tz,
freq=MonthEnd())
early_dr.union(late_dr)
示例3: test_is_superperiod_subperiod
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_is_superperiod_subperiod():
# input validation
assert not (is_superperiod(offsets.YearEnd(), None))
assert not (is_subperiod(offsets.MonthEnd(), None))
assert not (is_superperiod(None, offsets.YearEnd()))
assert not (is_subperiod(None, offsets.MonthEnd()))
assert not (is_superperiod(None, None))
assert not (is_subperiod(None, None))
assert (is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
assert (is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
assert (is_superperiod(offsets.Hour(), offsets.Minute()))
assert (is_subperiod(offsets.Minute(), offsets.Hour()))
assert (is_superperiod(offsets.Second(), offsets.Milli()))
assert (is_subperiod(offsets.Milli(), offsets.Second()))
assert (is_superperiod(offsets.Milli(), offsets.Micro()))
assert (is_subperiod(offsets.Micro(), offsets.Milli()))
assert (is_superperiod(offsets.Micro(), offsets.Nano()))
assert (is_subperiod(offsets.Nano(), offsets.Micro()))
示例4: test_month_range_union_tz_dateutil
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_month_range_union_tz_dateutil(self):
tm._skip_if_windows_python_3()
from pandas._libs.tslibs.timezones import dateutil_gettz
tz = dateutil_gettz('US/Eastern')
early_start = datetime(2011, 1, 1)
early_end = datetime(2011, 3, 1)
late_start = datetime(2011, 3, 1)
late_end = datetime(2011, 5, 1)
early_dr = date_range(start=early_start, end=early_end, tz=tz,
freq=MonthEnd())
late_dr = date_range(start=late_start, end=late_end, tz=tz,
freq=MonthEnd())
early_dr.union(late_dr)
示例5: test_is_superperiod_subperiod
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_is_superperiod_subperiod():
# input validation
assert not (frequencies.is_superperiod(offsets.YearEnd(), None))
assert not (frequencies.is_subperiod(offsets.MonthEnd(), None))
assert not (frequencies.is_superperiod(None, offsets.YearEnd()))
assert not (frequencies.is_subperiod(None, offsets.MonthEnd()))
assert not (frequencies.is_superperiod(None, None))
assert not (frequencies.is_subperiod(None, None))
assert (frequencies.is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
assert (frequencies.is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
assert (frequencies.is_superperiod(offsets.Hour(), offsets.Minute()))
assert (frequencies.is_subperiod(offsets.Minute(), offsets.Hour()))
assert (frequencies.is_superperiod(offsets.Second(), offsets.Milli()))
assert (frequencies.is_subperiod(offsets.Milli(), offsets.Second()))
assert (frequencies.is_superperiod(offsets.Milli(), offsets.Micro()))
assert (frequencies.is_subperiod(offsets.Micro(), offsets.Milli()))
assert (frequencies.is_superperiod(offsets.Micro(), offsets.Nano()))
assert (frequencies.is_subperiod(offsets.Nano(), offsets.Micro()))
示例6: test_setitem_ndarray
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_setitem_ndarray(self):
timeidx = date_range(start=datetime(2009, 1, 1),
end=datetime(2009, 12, 31),
freq=MonthEnd())
lons_coarse = np.linspace(-177.5, 177.5, 72)
lats_coarse = np.linspace(-87.5, 87.5, 36)
P = Panel(items=timeidx, major_axis=lons_coarse,
minor_axis=lats_coarse)
data = np.random.randn(72 * 36).reshape((72, 36))
key = datetime(2009, 2, 28)
P[key] = data
assert_almost_equal(P[key].values, data)
示例7: compare_index_period
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def compare_index_period(result, expected, typ, version):
tm.assert_index_equal(result, expected)
assert isinstance(result.freq, MonthEnd)
assert result.freq == MonthEnd()
assert result.freqstr == 'M'
tm.assert_index_equal(result.shift(2), expected.shift(2))
示例8: test_setitem_ndarray
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_setitem_ndarray(self):
with catch_warnings(record=True):
timeidx = date_range(start=datetime(2009, 1, 1),
end=datetime(2009, 12, 31),
freq=MonthEnd())
lons_coarse = np.linspace(-177.5, 177.5, 72)
lats_coarse = np.linspace(-87.5, 87.5, 36)
P = Panel(items=timeidx, major_axis=lons_coarse,
minor_axis=lats_coarse)
data = np.random.randn(72 * 36).reshape((72, 36))
key = datetime(2009, 2, 28)
P[key] = data
assert_almost_equal(P[key].values, data)
示例9: test_is_superperiod_subperiod
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_is_superperiod_subperiod():
assert(fmod.is_superperiod(offsets.YearEnd(), offsets.MonthEnd()))
assert(fmod.is_subperiod(offsets.MonthEnd(), offsets.YearEnd()))
assert(fmod.is_superperiod(offsets.Hour(), offsets.Minute()))
assert(fmod.is_subperiod(offsets.Minute(), offsets.Hour()))
示例10: eom
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def eom(d, offset=0):
"""Unmodified end-of-month. Returns the last date of month for the
same month and year as input d
The offset parameter represents the number of months that will be
added (if offset > 0) or subtracted (if offset < 0) to input date d.
This is especially useful for offset = -1, which gives you the EOM
of previous month, for example.
"""
d = to_datetime(d)
# Adding straight up the MonthEnd works as expected for MonthEnd(0),
# but it gives weird results if using MonthEnd(1) and the input is
# the last date of month. We leave the offset to a different function
return d + DateOffset(months=offset) + MonthEnd(0)
示例11: test_get_freq_code
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_get_freq_code(self):
# frequency str
assert (get_freq_code('A') ==
(get_freq('A'), 1))
assert (get_freq_code('3D') ==
(get_freq('D'), 3))
assert (get_freq_code('-2M') ==
(get_freq('M'), -2))
# tuple
assert (get_freq_code(('D', 1)) ==
(get_freq('D'), 1))
assert (get_freq_code(('A', 3)) ==
(get_freq('A'), 3))
assert (get_freq_code(('M', -2)) ==
(get_freq('M'), -2))
# numeric tuple
assert get_freq_code((1000, 1)) == (1000, 1)
# offsets
assert (get_freq_code(offsets.Day()) ==
(get_freq('D'), 1))
assert (get_freq_code(offsets.Day(3)) ==
(get_freq('D'), 3))
assert (get_freq_code(offsets.Day(-2)) ==
(get_freq('D'), -2))
assert (get_freq_code(offsets.MonthEnd()) ==
(get_freq('M'), 1))
assert (get_freq_code(offsets.MonthEnd(3)) ==
(get_freq('M'), 3))
assert (get_freq_code(offsets.MonthEnd(-2)) ==
(get_freq('M'), -2))
assert (get_freq_code(offsets.Week()) ==
(get_freq('W'), 1))
assert (get_freq_code(offsets.Week(3)) ==
(get_freq('W'), 3))
assert (get_freq_code(offsets.Week(-2)) ==
(get_freq('W'), -2))
# Monday is weekday=0
assert (get_freq_code(offsets.Week(weekday=1)) ==
(get_freq('W-TUE'), 1))
assert (get_freq_code(offsets.Week(3, weekday=0)) ==
(get_freq('W-MON'), 3))
assert (get_freq_code(offsets.Week(-2, weekday=4)) ==
(get_freq('W-FRI'), -2))
示例12: test_get_freq_code
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def test_get_freq_code(self):
# frequency str
assert (frequencies.get_freq_code('A') ==
(frequencies.get_freq('A'), 1))
assert (frequencies.get_freq_code('3D') ==
(frequencies.get_freq('D'), 3))
assert (frequencies.get_freq_code('-2M') ==
(frequencies.get_freq('M'), -2))
# tuple
assert (frequencies.get_freq_code(('D', 1)) ==
(frequencies.get_freq('D'), 1))
assert (frequencies.get_freq_code(('A', 3)) ==
(frequencies.get_freq('A'), 3))
assert (frequencies.get_freq_code(('M', -2)) ==
(frequencies.get_freq('M'), -2))
# numeric tuple
assert frequencies.get_freq_code((1000, 1)) == (1000, 1)
# offsets
assert (frequencies.get_freq_code(offsets.Day()) ==
(frequencies.get_freq('D'), 1))
assert (frequencies.get_freq_code(offsets.Day(3)) ==
(frequencies.get_freq('D'), 3))
assert (frequencies.get_freq_code(offsets.Day(-2)) ==
(frequencies.get_freq('D'), -2))
assert (frequencies.get_freq_code(offsets.MonthEnd()) ==
(frequencies.get_freq('M'), 1))
assert (frequencies.get_freq_code(offsets.MonthEnd(3)) ==
(frequencies.get_freq('M'), 3))
assert (frequencies.get_freq_code(offsets.MonthEnd(-2)) ==
(frequencies.get_freq('M'), -2))
assert (frequencies.get_freq_code(offsets.Week()) ==
(frequencies.get_freq('W'), 1))
assert (frequencies.get_freq_code(offsets.Week(3)) ==
(frequencies.get_freq('W'), 3))
assert (frequencies.get_freq_code(offsets.Week(-2)) ==
(frequencies.get_freq('W'), -2))
# Monday is weekday=0
assert (frequencies.get_freq_code(offsets.Week(weekday=1)) ==
(frequencies.get_freq('W-TUE'), 1))
assert (frequencies.get_freq_code(offsets.Week(3, weekday=0)) ==
(frequencies.get_freq('W-MON'), 3))
assert (frequencies.get_freq_code(offsets.Week(-2, weekday=4)) ==
(frequencies.get_freq('W-FRI'), -2))
示例13: load_shiller
# 需要导入模块: from pandas.tseries import offsets [as 别名]
# 或者: from pandas.tseries.offsets import MonthEnd [as 别名]
def load_shiller():
"""Load market & macroeconomic data from Robert Shiller's website.
Returns
-------
iedata : pd.DataFrame
Time series of S&P 500 and interest rate variables.
Example
-------
>>> from pyfinance import datasets
>>> shiller = datasets.load_shiller()
>>> shiller.iloc[:7, :5]
sp50p sp50d sp50e cpi real_rate
date
1871-01-31 4.44 0.26 0.4 12.4641 5.3200
1871-02-28 4.50 0.26 0.4 12.8446 5.3233
1871-03-31 4.61 0.26 0.4 13.0350 5.3267
1871-04-30 4.74 0.26 0.4 12.5592 5.3300
1871-05-31 4.86 0.26 0.4 12.2738 5.3333
1871-06-30 4.82 0.26 0.4 12.0835 5.3367
1871-07-31 4.73 0.26 0.4 12.0835 5.3400
.. _ONLINE DATA ROBERT SHILLER:
http://www.econ.yale.edu/~shiller/data.htm
"""
xls = "http://www.econ.yale.edu/~shiller/data/ie_data.xls"
cols = [
"date",
"sp50p",
"sp50d",
"sp50e",
"cpi",
"frac",
"real_rate",
"real_sp50p",
"real_sp50d",
"real_sp50e",
"cape",
]
iedata = pd.read_excel(
xls, sheet_name="Data", skiprows=7, skip_footer=1, names=cols
).drop("frac", axis=1)
dt = iedata["date"].astype(str).str.replace(".", "") + "01"
iedata["date"] = pd.to_datetime(dt, format="%Y%m%d") + offsets.MonthEnd()
return iedata.set_index("date")