本文整理匯總了Python中pandas.core.api.Series方法的典型用法代碼示例。如果您正苦於以下問題:Python api.Series方法的具體用法?Python api.Series怎麽用?Python api.Series使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.core.api
的用法示例。
在下文中一共展示了api.Series方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: asfreq
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def asfreq(obj, freq, method=None, how=None, normalize=False):
"""
Utility frequency conversion method for Series/DataFrame
"""
if isinstance(obj.index, PeriodIndex):
if method is not None:
raise NotImplementedError
if how is None:
how = 'E'
new_index = obj.index.asfreq(freq, how=how)
new_obj = obj.copy()
new_obj.index = new_index
return new_obj
else:
if len(obj.index) == 0:
return obj.copy()
dti = date_range(obj.index[0], obj.index[-1], freq=freq)
rs = obj.reindex(dti, method=method)
if normalize:
rs.index = rs.index.normalize()
return rs
示例2: _center_window
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def _center_window(rs, window, axis):
if axis > rs.ndim-1:
raise ValueError("Requested axis is larger then no. of argument dimensions")
offset = int((window - 1) / 2.)
if isinstance(rs, (Series, DataFrame, Panel)):
rs = rs.shift(-offset, axis=axis)
else:
rs_indexer = [slice(None)] * rs.ndim
rs_indexer[axis] = slice(None, -offset)
lead_indexer = [slice(None)] * rs.ndim
lead_indexer[axis] = slice(offset, None)
na_indexer = [slice(None)] * rs.ndim
na_indexer[axis] = slice(-offset, None)
rs[tuple(rs_indexer)] = np.copy(rs[tuple(lead_indexer)])
rs[tuple(na_indexer)] = np.nan
return rs
示例3: _process_data_structure
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def _process_data_structure(arg, kill_inf=True):
if isinstance(arg, DataFrame):
return_hook = lambda v: type(arg)(v, index=arg.index,
columns=arg.columns)
values = arg.values
elif isinstance(arg, Series):
values = arg.values
return_hook = lambda v: Series(v, arg.index)
else:
return_hook = lambda v: v
values = arg
if not issubclass(values.dtype.type, float):
values = values.astype(float)
if kill_inf:
values = values.copy()
values[np.isinf(values)] = np.NaN
return return_hook, values
#------------------------------------------------------------------------------
# Exponential moving moments
示例4: expanding_apply
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def expanding_apply(arg, func, min_periods=1, freq=None, center=False,
time_rule=None):
"""Generic expanding function application
Parameters
----------
arg : Series, DataFrame
func : function
Must produce a single value from an ndarray input
min_periods : int
Minimum number of observations in window required to have a value
freq : None or string alias / date offset object, default=None
Frequency to conform to before computing statistic
center : boolean, default False
Whether the label should correspond with center of window
time_rule : Legacy alias for freq
Returns
-------
y : type of input argument
"""
window = len(arg)
return rolling_apply(arg, window, func, min_periods=min_periods, freq=freq,
center=center, time_rule=time_rule)
示例5: expanding_count
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def expanding_count(arg, freq=None):
"""
Expanding count of number of non-NaN observations.
Parameters
----------
arg : DataFrame or numpy ndarray-like
freq : string or DateOffset object, optional (default None)
Frequency to conform the data to before computing the
statistic. Specified as a frequency string or DateOffset object.
Returns
-------
expanding_count : type of caller
Notes
-----
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).
To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return ensure_compat('expanding', 'count', arg, freq=freq)
示例6: _get_notna_col_dtype
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def _get_notna_col_dtype(self, col):
"""
Infer datatype of the Series col. In case the dtype of col is 'object'
and it contains NA values, this infers the datatype of the not-NA
values. Needed for inserting typed data containing NULLs, GH8778.
"""
col_for_inference = col
if col.dtype == 'object':
notnadata = col[~isna(col)]
if len(notnadata):
col_for_inference = notnadata
return lib.infer_dtype(col_for_inference)
示例7: _take_new_index
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def _take_new_index(obj, indexer, new_index, axis=0):
from pandas.core.api import Series, DataFrame
if isinstance(obj, Series):
new_values = com.take_1d(obj.values, indexer)
return Series(new_values, index=new_index, name=obj.name)
elif isinstance(obj, DataFrame):
if axis == 1:
raise NotImplementedError
return DataFrame(obj._data.take(indexer, new_index=new_index, axis=1))
else:
raise NotImplementedError
示例8: _prepare_data
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def _prepare_data(self):
"""
Cleans the input for single OLS.
Parameters
----------
lhs: Series
Dependent variable in the regression.
rhs: dict, whose values are Series, DataFrame, or dict
Explanatory variables of the regression.
Returns
-------
Series, DataFrame
Cleaned lhs and rhs
"""
(filt_lhs, filt_rhs, filt_weights,
pre_filt_rhs, index, valid) = _filter_data(self._y_orig, self._x_orig,
self._weights_orig)
if self._intercept:
filt_rhs['intercept'] = 1.
pre_filt_rhs['intercept'] = 1.
if hasattr(filt_weights,'to_dense'):
filt_weights = filt_weights.to_dense()
return (filt_lhs, filt_rhs, filt_weights,
pre_filt_rhs, index, valid)
示例9: beta
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def beta(self):
"""Returns the betas in Series form."""
return Series(self._beta_raw, index=self._x.columns)
示例10: p_value
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def p_value(self):
"""Returns the p values."""
return Series(self._p_value_raw, index=self.beta.index)
示例11: std_err
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def std_err(self):
"""Returns the standard err values of the betas."""
return Series(self._std_err_raw, index=self.beta.index)
示例12: t_stat
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def t_stat(self):
"""Returns the t-stat values of the betas."""
return Series(self._t_stat_raw, index=self.beta.index)
示例13: y_fitted
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def y_fitted(self):
"""Returns the fitted y values. This equals BX."""
if self._weights is None:
index = self._x_filtered.index
orig_index = index
else:
index = self._y.index
orig_index = self._y_orig.index
result = Series(self._y_fitted_raw, index=index)
return result.reindex(orig_index)
示例14: df
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def df(self):
"""Returns the degrees of freedom."""
return Series(self._df_raw, index=self._result_index)
示例15: df_model
# 需要導入模塊: from pandas.core import api [as 別名]
# 或者: from pandas.core.api import Series [as 別名]
def df_model(self):
"""Returns the model degrees of freedom."""
return Series(self._df_model_raw, index=self._result_index)