本文整理汇总了Python中statsmodels.datasets.macrodata.load_pandas函数的典型用法代码示例。如果您正苦于以下问题:Python load_pandas函数的具体用法?Python load_pandas怎么用?Python load_pandas使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_pandas函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
d = macrodata.load_pandas().data
# growth rates
d["gs_l_realinv"] = 400 * np.log(d["realinv"]).diff()
d["gs_l_realgdp"] = 400 * np.log(d["realgdp"]).diff()
d["lint"] = d["realint"].shift(1)
d["tbilrate"] = d["tbilrate"].shift(1)
d = d.dropna()
self.d = d
endogg = d["gs_l_realinv"]
exogg = add_constant(d[["gs_l_realgdp", "lint"]])
exogg2 = add_constant(d[["gs_l_realgdp", "tbilrate"]])
exogg3 = add_constant(d[["gs_l_realgdp"]])
res_ols = OLS(endogg, exogg).fit()
res_ols2 = OLS(endogg, exogg2).fit()
res_ols3 = OLS(endogg, exogg3).fit()
self.res = res_ols
self.res2 = res_ols2
self.res3 = res_ols3
self.endog = self.res.model.endog
self.exog = self.res.model.exog
示例2: test_stata_writer_pandas
def test_stata_writer_pandas():
buf = BytesIO()
dta = macrodata.load_pandas().data
dta4 = dta.copy()
for col in ('year','quarter'):
dta[col] = dta[col].astype(np.int64)
dta4[col] = dta4[col].astype(np.int32)
# dta is int64 'i8' given to Stata writer
with pytest.warns(FutureWarning):
writer = StataWriter(buf, dta)
with warnings.catch_warnings(record=True) as w:
writer.write_file()
assert len(w) == 0
buf.seek(0)
with pytest.warns(FutureWarning):
dta2 = genfromdta(buf)
dta5 = DataFrame.from_records(dta2)
# dta2 is int32 'i4' returned from Stata reader
if dta5.dtypes[1] is np.dtype('int64'):
ptesting.assert_frame_equal(dta.reset_index(), dta5)
else:
# don't check index because it has different size, int32 versus int64
ptesting.assert_frame_equal(dta4, dta5[dta5.columns[1:]])
示例3: setup_class
def setup_class(cls):
d = macrodata.load_pandas().data
#growth rates
d['gs_l_realinv'] = 400 * np.log(d['realinv']).diff()
d['gs_l_realgdp'] = 400 * np.log(d['realgdp']).diff()
d['lint'] = d['realint'].shift(1)
d['tbilrate'] = d['tbilrate'].shift(1)
d = d.dropna()
cls.d = d
endogg = d['gs_l_realinv']
exogg = add_constant(d[['gs_l_realgdp', 'lint']])
exogg2 = add_constant(d[['gs_l_realgdp', 'tbilrate']])
exogg3 = add_constant(d[['gs_l_realgdp']])
res_ols = OLS(endogg, exogg).fit()
res_ols2 = OLS(endogg, exogg2).fit()
res_ols3 = OLS(endogg, exogg3).fit()
cls.res = res_ols
cls.res2 = res_ols2
cls.res3 = res_ols3
cls.endog = cls.res.model.endog
cls.exog = cls.res.model.exog
示例4: setup_class
def setup_class(cls):
d2 = macrodata.load_pandas().data
g_gdp = 400*np.diff(np.log(d2['realgdp'].values))
g_inv = 400*np.diff(np.log(d2['realinv'].values))
exogg = add_constant(np.c_[g_gdp, d2['realint'][:-1].values], prepend=False)
cls.res1 = res_ols = OLS(g_inv, exogg).fit()
示例5: test_genfromdta_pandas
def test_genfromdta_pandas():
from pandas.util.testing import assert_frame_equal
dta = macrodata.load_pandas().data
curdir = os.path.dirname(os.path.abspath(__file__))
res1 = sm.iolib.genfromdta(curdir+'/../../datasets/macrodata/macrodata.dta',
pandas=True)
res1 = res1.astype(float)
assert_frame_equal(res1, dta)
示例6: t_est_webuse_pandas
def t_est_webuse_pandas():
# test copied and adjusted from iolib/tests/test_foreign
from pandas.util.testing import assert_frame_equal
from statsmodels.datasets import macrodata
dta = macrodata.load_pandas().data
base_gh = "http://github.com/statsmodels/statsmodels/raw/master/statsmodels/datasets/macrodata/"
res1 = webuse('macrodata', baseurl=base_gh)
res1 = res1.astype(float)
assert_frame_equal(res1, dta)
示例7: test_hpfilter_pandas
def test_hpfilter_pandas():
dta = macrodata.load_pandas().data
index = Index(dates_from_range('1959Q1', '2009Q3'))
dta.index = index
cycle, trend = hpfilter(dta["realgdp"])
ndcycle, ndtrend = hpfilter(dta['realgdp'].values)
assert_equal(cycle.values, ndcycle)
assert_equal(cycle.index[0], datetime(1959, 3, 31))
assert_equal(cycle.index[-1], datetime(2009, 9, 30))
assert_equal(cycle.name, "realgdp")
示例8: test_hpfilter_pandas
def test_hpfilter_pandas():
dta = macrodata.load_pandas().data
index = DatetimeIndex(start='1959-01-01', end='2009-10-01', freq='Q')
dta.index = index
cycle, trend = hpfilter(dta["realgdp"])
ndcycle, ndtrend = hpfilter(dta['realgdp'].values)
assert_equal(cycle.values, ndcycle)
assert_equal(cycle.index[0], datetime(1959, 3, 31))
assert_equal(cycle.index[-1], datetime(2009, 9, 30))
assert_equal(cycle.name, "realgdp")
示例9: test_genfromdta_pandas
def test_genfromdta_pandas():
from pandas.util.testing import assert_frame_equal
dta = macrodata.load_pandas().data
curdir = os.path.dirname(os.path.abspath(__file__))
with pytest.warns(FutureWarning):
res1 = genfromdta(curdir+'/../../datasets/macrodata/macrodata.dta',
pandas=True)
res1 = res1.astype(float)
assert_frame_equal(res1, dta.astype(float))
示例10: setup_class
def setup_class(cls):
d2 = macrodata.load_pandas().data
g_gdp = 400*np.diff(np.log(d2['realgdp'].values))
g_inv = 400*np.diff(np.log(d2['realinv'].values))
exogg = add_constant(np.c_[g_gdp, d2['realint'][:-1].values], prepend=False)
mod1 = GLSAR(g_inv, exogg, 1)
cls.res = mod1.iterative_fit(5)
from .results.macro_gr_corc_stata import results
cls.results = results
示例11: test_webuse_pandas
def test_webuse_pandas():
# test copied and adjusted from iolib/tests/test_foreign
from pandas.util.testing import assert_frame_equal
from statsmodels.datasets import macrodata
dta = macrodata.load_pandas().data
base_gh = "http://github.com/statsmodels/statsmodels/raw/master/statsmodels/datasets/macrodata/"
internet_available = check_internet(base_gh)
if not internet_available:
raise SkipTest('Unable to retrieve file - skipping test')
res1 = webuse('macrodata', baseurl=base_gh)
res1 = res1.astype(float)
assert_frame_equal(res1, dta)
示例12: test_grangercausality
def test_grangercausality(self):
# some example data
mdata = macrodata.load_pandas().data
mdata = mdata[['realgdp', 'realcons']].values
data = mdata.astype(float)
data = np.diff(np.log(data), axis=0)
#R: lmtest:grangertest
r_result = [0.243097, 0.7844328, 195, 2] # f_test
gr = grangercausalitytests(data[:, 1::-1], 2, verbose=False)
assert_almost_equal(r_result, gr[2][0]['ssr_ftest'], decimal=7)
assert_almost_equal(gr[2][0]['params_ftest'], gr[2][0]['ssr_ftest'], decimal=7)
示例13: test_webuse_pandas
def test_webuse_pandas():
# test copied and adjusted from iolib/tests/test_foreign
from pandas.util.testing import assert_frame_equal
from statsmodels.datasets import macrodata
dta = macrodata.load_pandas().data
base_gh = "https://github.com/statsmodels/statsmodels/raw/master/" \
"statsmodels/datasets/macrodata/"
internet_available = check_internet(base_gh)
if not internet_available:
pytest.skip('Unable to retrieve file - skipping test')
try:
res1 = webuse('macrodata', baseurl=base_gh)
except (HTTPError, URLError, SSLError, timeout):
pytest.skip('Failed with HTTP Error, these are random')
res1 = res1.astype(float)
assert_frame_equal(res1, dta.astype(float))
示例14: setup_class
def setup_class(cls):
import pandas as pd
from statsmodels.datasets import macrodata, co2
dta = macrodata.load_pandas().data
index = pd.PeriodIndex(start='1959Q1', end='2009Q3', freq='Q')
dta.index = index
cls.quarterly_data = dta.dropna()
dta = co2.load_pandas().data
dta['co2'] = dta.co2.interpolate()
cls.monthly_data = dta.resample('M')
# change in pandas 0.18 resample is deferred object
if not isinstance(cls.monthly_data, (pd.DataFrame, pd.Series)):
cls.monthly_data = cls.monthly_data.mean()
cls.monthly_start_data = dta.resample('MS')
if not isinstance(cls.monthly_start_data, (pd.DataFrame, pd.Series)):
cls.monthly_start_data = cls.monthly_start_data.mean()
示例15: setupClass
def setupClass(cls):
if not _have_x13:
raise SkipTest("X13/X12 not available")
import pandas as pd
from statsmodels.datasets import macrodata, co2
dta = macrodata.load_pandas().data
dates = dates_from_range("1959Q1", "2009Q3")
index = pd.DatetimeIndex(dates)
dta.index = index
cls.quarterly_data = dta.dropna()
dta = co2.load_pandas().data
dta["co2"] = dta.co2.interpolate()
cls.monthly_data = dta.resample("M")
cls.monthly_start_data = dta.resample("MS")