当前位置: 首页>>代码示例>>Python>>正文


Python base.Index方法代码示例

本文整理汇总了Python中pandas.core.indexes.base.Index方法的典型用法代码示例。如果您正苦于以下问题:Python base.Index方法的具体用法?Python base.Index怎么用?Python base.Index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.core.indexes.base的用法示例。


在下文中一共展示了base.Index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _simple_new

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def _simple_new(cls, start, stop=None, step=None, name=None,
                    dtype=None, **kwargs):
        result = object.__new__(cls)

        # handle passed None, non-integers
        if start is None and stop is None:
            # empty
            start, stop, step = 0, 0, 1

        if start is None or not is_integer(start):
            try:

                return RangeIndex(start, stop, step, name=name, **kwargs)
            except TypeError:
                return Index(start, stop, step, name=name, **kwargs)

        result._start = start
        result._stop = stop or 0
        result._step = step or 1
        result.name = name
        for k, v in compat.iteritems(kwargs):
            setattr(result, k, v)

        result._reset_identity()
        return result 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:range.py

示例2: equals

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def equals(self, other):
        """
        Determines if two CategorialIndex objects contain the same elements.
        """
        if self.is_(other):
            return True

        if not isinstance(other, Index):
            return False

        try:
            other = self._is_dtype_compat(other)
            return array_equivalent(self._data, other)
        except (TypeError, ValueError):
            pass

        return False 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:19,代码来源:category.py

示例3: _reindex_non_unique

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def _reindex_non_unique(self, target):
        """ reindex from a non-unique; which CategoricalIndex's are almost
        always
        """
        new_target, indexer = self.reindex(target)
        new_indexer = None

        check = indexer == -1
        if check.any():
            new_indexer = np.arange(len(self.take(indexer)))
            new_indexer[check] = -1

        cats = self.categories.get_indexer(target)
        if not (cats == -1).any():
            # .reindex returns normal Index. Revert to CategoricalIndex if
            # all targets are included in my categories
            new_target = self._shallow_copy(new_target)

        return new_target, indexer, new_indexer 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:21,代码来源:category.py

示例4: _convert_list_indexer

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def _convert_list_indexer(self, keyarr, kind=None):
        # Return our indexer or raise if all of the values are not included in
        # the categories

        if self.categories._defer_to_indexing:
            indexer = self.categories._convert_list_indexer(keyarr, kind=kind)
            return Index(self.codes).get_indexer_for(indexer)

        indexer = self.categories.get_indexer(np.asarray(keyarr))
        if (indexer == -1).any():
            raise KeyError(
                "a list-indexer must only "
                "include values that are "
                "in the categories")

        return self.get_indexer(keyarr) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:18,代码来源:category.py

示例5: __getitem__

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def __getitem__(self, value):
        left = self.left[value]
        right = self.right[value]

        # scalar
        if not isinstance(left, Index):
            if isna(left):
                return self._fill_value
            return Interval(left, right, self.closed)

        return self._shallow_copy(left, right) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:interval.py

示例6: left

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def left(self):
        """
        Return the left endpoints of each Interval in the IntervalArray as
        an Index
        """
        return self._left 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:interval.py

示例7: right

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def right(self):
        """
        Return the right endpoints of each Interval in the IntervalArray as
        an Index
        """
        return self._right 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:interval.py

示例8: length

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def length(self):
        """
        Return an Index with entries denoting the length of each Interval in
        the IntervalArray
        """
        try:
            return self.right - self.left
        except TypeError:
            # length not defined for some types, e.g. string
            msg = ('IntervalArray contains Intervals without defined length, '
                   'e.g. Intervals with string endpoints')
            raise TypeError(msg) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:interval.py

示例9: mid

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def mid(self):
        """
        Return the midpoint of each Interval in the IntervalArray as an Index
        """
        try:
            return 0.5 * (self.left + self.right)
        except TypeError:
            # datetime safe version
            return self.left + 0.5 * self.length 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:interval.py

示例10: equals

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def equals(self, other):
        """
        Determines if two Index objects contain the same elements.
        """
        if isinstance(other, RangeIndex):
            ls = len(self)
            lo = len(other)
            return (ls == lo == 0 or
                    ls == lo == 1 and
                    self._start == other._start or
                    ls == lo and
                    self._start == other._start and
                    self._step == other._step)

        return super(RangeIndex, self).equals(other) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:range.py

示例11: is_monotonic_increasing

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def is_monotonic_increasing(self):
        return Index(self.codes).is_monotonic_increasing 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:4,代码来源:category.py

示例12: is_monotonic_decreasing

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def is_monotonic_decreasing(self):
        return Index(self.codes).is_monotonic_decreasing 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:4,代码来源:category.py

示例13: delete

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def delete(self, loc):
        """
        Make new Index with passed location(-s) deleted

        Returns
        -------
        new_index : Index
        """
        return self._create_from_codes(np.delete(self.codes, loc)) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:11,代码来源:category.py

示例14: insert

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def insert(self, loc, item):
        """
        Make new Index inserting new item at location. Follows
        Python list.append semantics for negative values

        Parameters
        ----------
        loc : int
        item : object

        Returns
        -------
        new_index : Index

        Raises
        ------
        ValueError if the item is not in the categories

        """
        code = self.categories.get_indexer([item])
        if (code == -1):
            raise TypeError("cannot insert an item into a CategoricalIndex "
                            "that is not already an existing category")

        codes = self.codes
        codes = np.concatenate((codes[:loc], code, codes[loc:]))
        return self._create_from_codes(codes) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:29,代码来源:category.py

示例15: _add_comparison_methods

# 需要导入模块: from pandas.core.indexes import base [as 别名]
# 或者: from pandas.core.indexes.base import Index [as 别名]
def _add_comparison_methods(cls):
        """ add in comparison methods """

        def _make_compare(op):
            def _evaluate_compare(self, other):

                # if we have a Categorical type, then must have the same
                # categories
                if isinstance(other, CategoricalIndex):
                    other = other._values
                elif isinstance(other, Index):
                    other = self._create_categorical(
                        self, other._values, categories=self.categories,
                        ordered=self.ordered)

                if isinstance(other, (ABCCategorical, np.ndarray,
                                      ABCSeries)):
                    if len(self.values) != len(other):
                        raise ValueError("Lengths must match to compare")

                if isinstance(other, ABCCategorical):
                    if not self.values.is_dtype_equal(other):
                        raise TypeError("categorical index comparisions must "
                                        "have the same categories and ordered "
                                        "attributes")

                return getattr(self.values, op)(other)

            return _evaluate_compare

        cls.__eq__ = _make_compare('__eq__')
        cls.__ne__ = _make_compare('__ne__')
        cls.__lt__ = _make_compare('__lt__')
        cls.__gt__ = _make_compare('__gt__')
        cls.__le__ = _make_compare('__le__')
        cls.__ge__ = _make_compare('__ge__') 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:38,代码来源:category.py


注:本文中的pandas.core.indexes.base.Index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。