本文整理汇总了Python中pandas.core.indexing.maybe_convert_indices方法的典型用法代码示例。如果您正苦于以下问题:Python indexing.maybe_convert_indices方法的具体用法?Python indexing.maybe_convert_indices怎么用?Python indexing.maybe_convert_indices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.indexing
的用法示例。
在下文中一共展示了indexing.maybe_convert_indices方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: take
# 需要导入模块: from pandas.core import indexing [as 别名]
# 或者: from pandas.core.indexing import maybe_convert_indices [as 别名]
def take(self, indexer, axis=1, verify=True, convert=True):
"""
Take items along any axis.
"""
self._consolidate_inplace()
indexer = (np.arange(indexer.start, indexer.stop, indexer.step,
dtype='int64')
if isinstance(indexer, slice)
else np.asanyarray(indexer, dtype='int64'))
n = self.shape[axis]
if convert:
indexer = maybe_convert_indices(indexer, n)
if verify:
if ((indexer == -1) | (indexer >= n)).any():
raise Exception('Indices must be nonzero and less than '
'the axis length')
new_labels = self.axes[axis].take(indexer)
return self.reindex_indexer(new_axis=new_labels, indexer=indexer,
axis=axis, allow_dups=True)
示例2: _convert_list_indexer
# 需要导入模块: from pandas.core import indexing [as 别名]
# 或者: from pandas.core.indexing import maybe_convert_indices [as 别名]
def _convert_list_indexer(self, keyarr, kind=None):
if (kind in [None, 'iloc', 'ix'] and
is_integer_dtype(keyarr) and not self.is_floating() and
not isinstance(keyarr, ABCPeriodIndex)):
if self.inferred_type == 'mixed-integer':
indexer = self.get_indexer(keyarr)
if (indexer >= 0).all():
return indexer
# missing values are flagged as -1 by get_indexer and negative
# indices are already converted to positive indices in the
# above if-statement, so the negative flags are changed to
# values outside the range of indices so as to trigger an
# IndexError in maybe_convert_indices
indexer[indexer < 0] = len(self)
from pandas.core.indexing import maybe_convert_indices
return maybe_convert_indices(indexer, len(self))
elif not self.inferred_type == 'integer':
keyarr = np.where(keyarr < 0, len(self) + keyarr, keyarr)
return keyarr
return None
示例3: _take
# 需要导入模块: from pandas.core import indexing [as 别名]
# 或者: from pandas.core.indexing import maybe_convert_indices [as 别名]
def _take(self, indices, axis=0, is_copy=False):
indices = ensure_platform_int(indices)
new_index = self.index.take(indices)
if is_categorical_dtype(self):
# https://github.com/pandas-dev/pandas/issues/20664
# TODO: remove when the default Categorical.take behavior changes
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
kwargs = {'allow_fill': False}
else:
kwargs = {}
new_values = self._values.take(indices, **kwargs)
result = (self._constructor(new_values, index=new_index,
fastpath=True).__finalize__(self))
# Maybe set copy if we didn't actually change the index.
if is_copy:
if not result._get_axis(axis).equals(self._get_axis(axis)):
result._set_is_copy(self)
return result
示例4: _take
# 需要导入模块: from pandas.core import indexing [as 别名]
# 或者: from pandas.core.indexing import maybe_convert_indices [as 别名]
def _take(self, indices, axis=0, is_copy=False):
indices = _ensure_platform_int(indices)
new_index = self.index.take(indices)
if is_categorical_dtype(self):
# https://github.com/pandas-dev/pandas/issues/20664
# TODO: remove when the default Categorical.take behavior changes
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
kwargs = {'allow_fill': False}
else:
kwargs = {}
new_values = self._values.take(indices, **kwargs)
result = (self._constructor(new_values, index=new_index,
fastpath=True).__finalize__(self))
# Maybe set copy if we didn't actually change the index.
if is_copy:
if not result._get_axis(axis).equals(self._get_axis(axis)):
result._set_is_copy(self)
return result
示例5: _take
# 需要导入模块: from pandas.core import indexing [as 别名]
# 或者: from pandas.core.indexing import maybe_convert_indices [as 别名]
def _take(self, indices, axis=0, convert=True, is_copy=False):
if convert:
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
indices = _ensure_platform_int(indices)
new_index = self.index.take(indices)
new_values = self._values.take(indices)
result = (self._constructor(new_values, index=new_index,
fastpath=True).__finalize__(self))
# Maybe set copy if we didn't actually change the index.
if is_copy:
if not result._get_axis(axis).equals(self._get_axis(axis)):
result._set_is_copy(self)
return result
示例6: _preprocess_slice_or_indexer
# 需要导入模块: from pandas.core import indexing [as 别名]
# 或者: from pandas.core.indexing import maybe_convert_indices [as 别名]
def _preprocess_slice_or_indexer(slice_or_indexer, length, allow_fill):
if isinstance(slice_or_indexer, slice):
return ('slice', slice_or_indexer,
libinternals.slice_len(slice_or_indexer, length))
elif (isinstance(slice_or_indexer, np.ndarray) and
slice_or_indexer.dtype == np.bool_):
return 'mask', slice_or_indexer, slice_or_indexer.sum()
else:
indexer = np.asanyarray(slice_or_indexer, dtype=np.int64)
if not allow_fill:
indexer = maybe_convert_indices(indexer, length)
return 'fancy', indexer, len(indexer)
示例7: _preprocess_slice_or_indexer
# 需要导入模块: from pandas.core import indexing [as 别名]
# 或者: from pandas.core.indexing import maybe_convert_indices [as 别名]
def _preprocess_slice_or_indexer(slice_or_indexer, length, allow_fill):
if isinstance(slice_or_indexer, slice):
return 'slice', slice_or_indexer, lib.slice_len(slice_or_indexer,
length)
elif (isinstance(slice_or_indexer, np.ndarray) and
slice_or_indexer.dtype == np.bool_):
return 'mask', slice_or_indexer, slice_or_indexer.sum()
else:
indexer = np.asanyarray(slice_or_indexer, dtype=np.int64)
if not allow_fill:
indexer = maybe_convert_indices(indexer, length)
return 'fancy', indexer, len(indexer)