本文整理匯總了Python中pandas.core.frame.DataFrame.iteritems方法的典型用法代碼示例。如果您正苦於以下問題:Python DataFrame.iteritems方法的具體用法?Python DataFrame.iteritems怎麽用?Python DataFrame.iteritems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.core.frame.DataFrame
的用法示例。
在下文中一共展示了DataFrame.iteritems方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: VAR
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import iteritems [as 別名]
class VAR(object):
"""
Estimates VAR(p) regression on multivariate time series data
presented in pandas data structures.
Parameters
----------
data : DataFrame or dict of Series
p : lags to include
"""
def __init__(self, data, p=1, intercept=True):
try:
import statsmodels.tsa.vector_ar.api as sm_var
except ImportError:
import scikits.statsmodels.tsa.var as sm_var
self._data = DataFrame(_combine_rhs(data))
self._p = p
self._columns = self._data.columns
self._index = self._data.index
self._intercept = intercept
@cache_readonly
def aic(self):
"""Returns the Akaike information criterion."""
return self._ic['aic']
@cache_readonly
def bic(self):
"""Returns the Bayesian information criterion."""
return self._ic['bic']
@cache_readonly
def beta(self):
"""
Returns a DataFrame, where each column x1 contains the betas
calculated by regressing the x1 column of the VAR input with
the lagged input.
Returns
-------
DataFrame
"""
d = dict([(key, value.beta)
for (key, value) in self.ols_results.iteritems()])
return DataFrame(d)
def forecast(self, h):
"""
Returns a DataFrame containing the forecasts for 1, 2, ..., n time
steps. Each column x1 contains the forecasts of the x1 column.
Parameters
----------
n: int
Number of time steps ahead to forecast.
Returns
-------
DataFrame
"""
forecast = self._forecast_raw(h)[:, 0, :]
return DataFrame(forecast, index=xrange(1, 1 + h),
columns=self._columns)
def forecast_cov(self, h):
"""
Returns the covariance of the forecast residuals.
Returns
-------
DataFrame
"""
return [DataFrame(value, index=self._columns, columns=self._columns)
for value in self._forecast_cov_raw(h)]
def forecast_std_err(self, h):
"""
Returns the standard errors of the forecast residuals.
Returns
-------
DataFrame
"""
return DataFrame(self._forecast_std_err_raw(h),
index=xrange(1, 1 + h), columns=self._columns)
@cache_readonly
def granger_causality(self):
"""Returns the f-stats and p-values from the Granger Causality Test.
If the data consists of columns x1, x2, x3, then we perform the
following regressions:
x1 ~ L(x2, x3)
x1 ~ L(x1, x3)
#.........這裏部分代碼省略.........
示例2: get_chunk
# 需要導入模塊: from pandas.core.frame import DataFrame [as 別名]
# 或者: from pandas.core.frame.DataFrame import iteritems [as 別名]
def get_chunk(self, rows=None):
if rows is not None and self.skip_footer:
raise ValueError('skip_footer not supported for iteration')
try:
content = self._get_lines(rows)
except StopIteration:
if self._first_chunk:
content = []
else:
raise
# done with first read, next time raise StopIteration
self._first_chunk = False
if len(content) == 0: # pragma: no cover
if self.index_col is not None:
if np.isscalar(self.index_col):
index = Index([], name=self.index_name)
else:
index = MultiIndex.from_arrays([[]] * len(self.index_col),
names=self.index_name)
else:
index = Index([])
return DataFrame(index=index, columns=self.columns)
zipped_content = list(lib.to_object_array(content).T)
if not self._has_complex_date_col and self.index_col is not None:
index = self._get_simple_index(zipped_content)
index = self._agg_index(index)
else:
index = Index(np.arange(len(content)))
col_len, zip_len = len(self.columns), len(zipped_content)
if col_len != zip_len:
row_num = -1
for (i, l) in enumerate(content):
if len(l) != col_len:
break
footers = 0
if self.skip_footer:
footers = self.skip_footer
row_num = self.pos - (len(content) - i + footers)
msg = ('Expecting %d columns, got %d in row %d' %
(col_len, zip_len, row_num))
raise ValueError(msg)
data = dict((k, v) for k, v in izip(self.columns, zipped_content))
# apply converters
for col, f in self.converters.iteritems():
if isinstance(col, int) and col not in self.columns:
col = self.columns[col]
data[col] = lib.map_infer(data[col], f)
columns = list(self.columns)
if self.parse_dates is not None:
data, columns = self._process_date_conversion(data)
data = _convert_to_ndarrays(data, self.na_values, self.verbose)
df = DataFrame(data=data, columns=columns, index=index)
if self._has_complex_date_col and self.index_col is not None:
if not self._name_processed:
self.index_name = self._get_index_name(list(columns))
self._name_processed = True
data = dict(((k, v) for k, v in df.iteritems()))
index = self._get_complex_date_index(data, col_names=columns,
parse_dates=False)
index = self._agg_index(index, False)
data = dict(((k, v.values) for k, v in data.iteritems()))
df = DataFrame(data=data, columns=columns, index=index)
if self.squeeze and len(df.columns) == 1:
return df[df.columns[0]]
return df