本文整理匯總了Python中pandas.core.generic.NDFrame方法的典型用法代碼示例。如果您正苦於以下問題:Python generic.NDFrame方法的具體用法?Python generic.NDFrame怎麽用?Python generic.NDFrame使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.core.generic
的用法示例。
在下文中一共展示了generic.NDFrame方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_iterator
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def get_iterator(self, data, axis=0):
"""
Groupby iterator
Returns
-------
Generator yielding sequence of (name, subsetted object)
for each group
"""
if isinstance(data, NDFrame):
slicer = lambda start, edge: data._slice(
slice(start, edge), axis=axis)
length = len(data.axes[axis])
else:
slicer = lambda start, edge: data[slice(start, edge)]
length = len(data)
start = 0
for edge, label in zip(self.bins, self.binlabels):
if label is not NaT:
yield label, slicer(start, edge)
start = edge
if start < length:
yield self.binlabels[-1], slicer(start, None)
示例2: get_group
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def get_group(self, name, obj=None):
"""
Constructs NDFrame from group with provided name.
Parameters
----------
name : object
the name of the group to get as a DataFrame
obj : NDFrame, default None
the NDFrame to take the DataFrame out of. If
it is None, the object groupby was called on will
be used
Returns
-------
group : same type as obj
"""
if obj is None:
obj = self._selected_obj
inds = self._get_index(name)
if not len(inds):
raise KeyError(name)
return obj._take(inds, axis=self.axis)
示例3: _multi_take_opportunity
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def _multi_take_opportunity(self, tup):
from pandas.core.generic import NDFrame
# ugly hack for GH #836
if not isinstance(self.obj, NDFrame):
return False
if not all(is_list_like_indexer(x) for x in tup):
return False
# just too complicated
for indexer, ax in zip(tup, self.obj._data.axes):
if isinstance(ax, MultiIndex):
return False
elif com.is_bool_indexer(indexer):
return False
elif not ax.is_unique:
return False
return True
示例4: get_group
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def get_group(self, name, obj=None):
"""
Constructs NDFrame from group with provided name
Parameters
----------
name : object
the name of the group to get as a DataFrame
obj : NDFrame, default None
the NDFrame to take the DataFrame out of. If
it is None, the object groupby was called on will
be used
Returns
-------
group : type of obj
"""
if obj is None:
obj = self._selected_obj
inds = self._get_index(name)
if not len(inds):
raise KeyError(name)
return obj._take(inds, axis=self.axis)
示例5: _multi_take_opportunity
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def _multi_take_opportunity(self, tup):
from pandas.core.generic import NDFrame
# ugly hack for GH #836
if not isinstance(self.obj, NDFrame):
return False
if not all(_is_list_like(x) for x in tup):
return False
# just too complicated
for indexer, ax in zip(tup, self.obj._data.axes):
if isinstance(ax, MultiIndex):
return False
elif com._is_bool_indexer(indexer):
return False
return True
示例6: get_group
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def get_group(self, name, obj=None):
"""
Constructs NDFrame from group with provided name
Parameters
----------
name : object
the name of the group to get as a DataFrame
obj : NDFrame, default None
the NDFrame to take the DataFrame out of. If
it is None, the object groupby was called on will
be used
Returns
-------
group : type of obj
"""
if obj is None:
obj = self.obj
inds = self._get_index(name)
return obj.take(inds, axis=self.axis, convert=False)
示例7: __init__
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def __init__(self, ndFrame=None, nodeName='', fileName='', standAlone=True,
iconColor=_defaultIconColor):
""" Constructor
The NDFrame is not part of Pandas' documented API, although it mentions this
inheritance. Therefore it is not checked the ndFrame is actually of type NDFrame.
:param ndFrame: the underlying pandas object. May be undefined (None)
:type ndFrame: pandas.core.generic.NDFrame
:param standAlone: True if the NDFrame is a stand-alone object, False if it is part of
another higher-dimensional, NDFrame. This influences the array. Furthermore, if
standAlone is True the index of the NDFrame will be included when the children
are fetched and included in the tree (as a PandasIndexRti)
"""
super(AbstractPandasNDFrameRti, self).__init__(nodeName=nodeName, fileName=fileName)
check_class(ndFrame, NDFrame, allow_none=True)
self._ndFrame = ndFrame
self._iconColor = iconColor
self._standAlone = standAlone
示例8: _flatten_data
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def _flatten_data(data, chart_cfg, switch_zy=False):
plot_axes_def = [(0, XAxis), (1, YAxis)]
# Inject categories into the axis definitions of the plot
if isinstance(data, NDFrame):
for i, plot_axis in plot_axes_def[:data.ndim]:
categories = data.axes[i]
# Skip numeric indices
if not categories.is_numeric():
chart_cfg = chart_cfg.inherit_many(plot_axis(categories=list(categories)))
data = [list(index) + [value] for index, value in list(np.ndenumerate(data))]
if switch_zy:
for i in range(len(data)):
tmp = data[i][-1]
data[i][-1] = data[i][-2]
data[i][-2] = tmp
return data, chart_cfg
示例9: _choose_chart_class
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def _choose_chart_class(data):
"""
Tries to guess the appropriate chart class based on the data.
"""
# In case the data has an index and the first entry is a datetime type, return a stock chart
# specialized for viewing time series.
if isinstance(data, pd.Series):
if isinstance(data.index[0], (np.datetime64, datetime)):
return "StockChart"
elif isinstance(data, NDFrame):
for labels in data.axes:
if isinstance(labels[0], (np.datetime64, datetime)):
return "StockChart"
elif hasattr(data, "__getitem__"):
try:
if isinstance(data[0], Plot):
return data[0]._chart_cls
if (len(data[0]) > 1) \
and isinstance(data[0], (list, tuple)) \
and isinstance(data[0][0], (np.datetime64, datetime)):
return "StockChart"
except TypeError:
pass
return "Chart"
示例10: _multi_take_opportunity
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def _multi_take_opportunity(self, tup):
from pandas.core.generic import NDFrame
# ugly hack for GH #836
if not isinstance(self.obj, NDFrame):
return False
if not all(is_list_like_indexer(x) for x in tup):
return False
# just too complicated
for indexer, ax in zip(tup, self.obj._data.axes):
if isinstance(ax, MultiIndex):
return False
elif is_bool_indexer(indexer):
return False
elif not ax.is_unique:
return False
return True
示例11: get_group
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def get_group(self, name, obj=None):
"""
Constructs NDFrame from group with provided name
Parameters
----------
name : object
the name of the group to get as a DataFrame
obj : NDFrame, default None
the NDFrame to take the DataFrame out of. If
it is None, the object groupby was called on will
be used
Returns
-------
group : type of obj
"""
if obj is None:
obj = self._selected_obj
inds = self._get_index(name)
if not len(inds):
raise KeyError(name)
return obj._take(inds, axis=self.axis, convert=False)
示例12: __getattr__
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def __getattr__(self, item):
if self._pandas_only:
raise SkipTest("empyrical.%s expects pandas-only inputs that have "
"dt indices/labels" % item)
func = super(ConvertPandasEmpyricalProxy, self).__getattr__(item)
@wraps(func)
def convert_args(*args, **kwargs):
args = [self._convert(arg) if isinstance(arg, NDFrame) else arg
for arg in args]
kwargs = {
k: self._convert(v) if isinstance(v, NDFrame) else v
for k, v in iteritems(kwargs)
}
return func(*args, **kwargs)
return convert_args
示例13: _update_inplace
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def _update_inplace(self, result, **kwargs):
# we want to call the generic version and not the IndexOpsMixin
return generic.NDFrame._update_inplace(self, result, **kwargs)
示例14: __init__
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def __init__(self, obj, keys=None, axis=0, level=None,
grouper=None, exclusions=None, selection=None, as_index=True,
sort=True, group_keys=True, squeeze=False,
observed=False, **kwargs):
self._selection = selection
if isinstance(obj, NDFrame):
obj._consolidate_inplace()
self.level = level
if not as_index:
if not isinstance(obj, DataFrame):
raise TypeError('as_index=False only valid with DataFrame')
if axis != 0:
raise ValueError('as_index=False only valid for axis=0')
self.as_index = as_index
self.keys = keys
self.sort = sort
self.group_keys = group_keys
self.squeeze = squeeze
self.observed = observed
self.mutated = kwargs.pop('mutated', False)
if grouper is None:
grouper, exclusions, obj = _get_grouper(obj, keys,
axis=axis,
level=level,
sort=sort,
observed=observed,
mutated=self.mutated)
self.obj = obj
self.axis = obj._get_axis_number(axis)
self.grouper = grouper
self.exclusions = set(exclusions) if exclusions else set()
# we accept no other args
validate_kwargs('group', kwargs, {})
示例15: __init__
# 需要導入模塊: from pandas.core import generic [as 別名]
# 或者: from pandas.core.generic import NDFrame [as 別名]
def __init__(self, obj, keys=None, axis=0, level=None,
grouper=None, exclusions=None, selection=None, as_index=True,
sort=True, group_keys=True, squeeze=False):
self._selection = selection
if isinstance(obj, NDFrame):
obj._consolidate_inplace()
self.obj = obj
self.axis = obj._get_axis_number(axis)
self.level = level
if not as_index:
if not isinstance(obj, DataFrame):
raise TypeError('as_index=False only valid with DataFrame')
if axis != 0:
raise ValueError('as_index=False only valid for axis=0')
self.as_index = as_index
self.keys = keys
self.sort = sort
self.group_keys = group_keys
self.squeeze = squeeze
if grouper is None:
grouper, exclusions = _get_grouper(obj, keys, axis=axis,
level=level, sort=sort)
self.grouper = grouper
self.exclusions = set(exclusions) if exclusions else set()