當前位置: 首頁>>代碼示例>>Python>>正文


Python indexing.maybe_convert_indices方法代碼示例

本文整理匯總了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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:managers.py

示例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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:base.py

示例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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:series.py

示例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 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:series.py

示例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 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:19,代碼來源:series.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:managers.py

示例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) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:14,代碼來源:internals.py


注:本文中的pandas.core.indexing.maybe_convert_indices方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。