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


Python series.Series方法代码示例

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


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

示例1: xs

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def xs(self, key, axis=0, copy=False):
        """
        Returns a row (cross-section) from the SparseDataFrame as a Series
        object.

        Parameters
        ----------
        key : some index contained in the index

        Returns
        -------
        xs : Series
        """
        if axis == 1:
            data = self[key]
            return data

        i = self.index.get_loc(key)
        data = self.take([i]).get_values()[0]
        return Series(data, index=self.columns)

    # ----------------------------------------------------------------------
    # Arithmetic-related methods 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:frame.py

示例2: _join_index

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def _join_index(self, other, how, lsuffix, rsuffix):
        if isinstance(other, Series):
            if other.name is None:
                raise ValueError('Other Series must have a name')

            other = SparseDataFrame(
                {other.name: other},
                default_fill_value=self._default_fill_value)

        join_index = self.index.join(other.index, how=how)

        this = self.reindex(join_index)
        other = other.reindex(join_index)

        this, other = this._maybe_rename_join(other, lsuffix, rsuffix)

        from pandas import concat
        return concat([this, other], axis=1, verify_integrity=True) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:frame.py

示例3: arrays_to_mgr

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def arrays_to_mgr(arrays, arr_names, index, columns, dtype=None):
    """
    Segregate Series based on type and coerce into matrices.

    Needs to handle a lot of exceptional cases.
    """
    # figure out the index, if necessary
    if index is None:
        index = extract_index(arrays)
    else:
        index = ensure_index(index)

    # don't force copy because getting jammed in an ndarray anyway
    arrays = _homogenize(arrays, index, dtype)

    # from BlockManager perspective
    axes = [ensure_index(columns), index]

    return create_block_manager_from_arrays(arrays, arr_names, axes) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:construction.py

示例4: _convert_object_array

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def _convert_object_array(content, columns, coerce_float=False, dtype=None):
    if columns is None:
        columns = ibase.default_index(len(content))
    else:
        if len(columns) != len(content):  # pragma: no cover
            # caller's responsibility to check for this...
            raise AssertionError('{col:d} columns passed, passed data had '
                                 '{con} columns'.format(col=len(columns),
                                                        con=len(content)))

    # provide soft conversion of object dtypes
    def convert(arr):
        if dtype != object and dtype != np.object:
            arr = lib.maybe_convert_objects(arr, try_float=coerce_float)
            arr = maybe_cast_to_datetime(arr, dtype)
        return arr

    arrays = [convert(arr) for arr in content]

    return arrays, columns


# ---------------------------------------------------------------------
# Series-Based 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:construction.py

示例5: _aggregate_series_fast

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def _aggregate_series_fast(self, obj, func):
        func = self._is_builtin_func(func)

        if obj.index._has_complex_internals:
            raise TypeError('Incompatible index for Cython grouper')

        group_index, _, ngroups = self.group_info

        # avoids object / Series creation overhead
        dummy = obj._get_values(slice(None, 0)).to_dense()
        indexer = get_group_index_sorter(group_index, ngroups)
        obj = obj._take(indexer).to_dense()
        group_index = algorithms.take_nd(
            group_index, indexer, allow_fill=False)
        grouper = reduction.SeriesGrouper(obj, func, group_index, ngroups,
                                          dummy)
        result, counts = grouper.get_result()
        return result, counts 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:ops.py

示例6: _aggregate_series_pure_python

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def _aggregate_series_pure_python(self, obj, func):

        group_index, _, ngroups = self.group_info

        counts = np.zeros(ngroups, dtype=int)
        result = None

        splitter = get_splitter(obj, group_index, ngroups, axis=self.axis)

        for label, group in splitter:
            res = func(group)
            if result is None:
                if (isinstance(res, (Series, Index, np.ndarray))):
                    raise ValueError('Function does not reduce')
                result = np.empty(ngroups, dtype='O')

            counts[label] = group.shape[0]
            result[label] = res

        result = lib.maybe_convert_objects(result, try_float=0)
        return result, counts 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:ops.py

示例7: _str_extract_frame

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def _str_extract_frame(arr, pat, flags=0):
    """
    For each subject string in the Series, extract groups from the
    first match of regular expression pat. This function is called from
    str_extract(expand=True), and always returns a DataFrame.

    """
    from pandas import DataFrame

    regex = re.compile(pat, flags=flags)
    groups_or_na = _groups_or_na_fun(regex)
    names = dict(zip(regex.groupindex.values(), regex.groupindex.keys()))
    columns = [names.get(1 + i, i) for i in range(regex.groups)]

    if len(arr) == 0:
        return DataFrame(columns=columns, dtype=object)
    try:
        result_index = arr.index
    except AttributeError:
        result_index = None
    return DataFrame(
        [groups_or_na(val) for val in arr],
        columns=columns,
        index=result_index,
        dtype=object) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:strings.py

示例8: str_slice

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def str_slice(arr, start=None, stop=None, step=None):
    """
    Slice substrings from each element in the Series/Index

    Parameters
    ----------
    start : int or None
    stop : int or None
    step : int or None

    Returns
    -------
    sliced : Series/Index of objects
    """
    obj = slice(start, stop, step)
    f = lambda x: x[obj]
    return _na_map(f, arr) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:strings.py

示例9: str_strip

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def str_strip(arr, to_strip=None, side='both'):
    """
    Strip whitespace (including newlines) from each string in the
    Series/Index.

    Parameters
    ----------
    to_strip : str or unicode
    side : {'left', 'right', 'both'}, default 'both'

    Returns
    -------
    stripped : Series/Index of objects
    """
    if side == 'both':
        f = lambda x: x.strip(to_strip)
    elif side == 'left':
        f = lambda x: x.lstrip(to_strip)
    elif side == 'right':
        f = lambda x: x.rstrip(to_strip)
    else:  # pragma: no cover
        raise ValueError('Invalid side')
    return _na_map(f, arr) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:strings.py

示例10: str_encode

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def str_encode(arr, encoding, errors="strict"):
    """
    Encode character string in the Series/Index using indicated encoding.
    Equivalent to :meth:`str.encode`.

    Parameters
    ----------
    encoding : str
    errors : str, optional

    Returns
    -------
    encoded : Series/Index of objects
    """
    if encoding in _cpython_optimized_encoders:
        # CPython optimized implementation
        f = lambda x: x.encode(encoding, errors)
    else:
        encoder = codecs.getencoder(encoding)
        f = lambda x: encoder(x, errors)[0]
    return _na_map(f, arr) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:23,代码来源:strings.py

示例11: zfill

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def zfill(self, width):
        """
        Filling left side of strings in the Series/Index with 0.
        Equivalent to :meth:`str.zfill`.

        Parameters
        ----------
        width : int
            Minimum width of resulting string; additional characters will be
            filled with 0

        Returns
        -------
        filled : Series/Index of objects
        """
        result = str_pad(self._data, width, side='left', fillchar='0')
        return self._wrap_result(result) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:strings.py

示例12: normalize

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def normalize(self, form):
        """Return the Unicode normal form for the strings in the Series/Index.
        For more information on the forms, see the
        :func:`unicodedata.normalize`.

        Parameters
        ----------
        form : {'NFC', 'NFKC', 'NFD', 'NFKD'}
            Unicode form

        Returns
        -------
        normalized : Series/Index of objects
        """
        import unicodedata
        f = lambda x: unicodedata.normalize(form, compat.u_safe(x))
        result = _na_map(f, self._data)
        return self._wrap_result(result) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:strings.py

示例13: xs

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def xs(self, key, axis=0, copy=False):
        """
        Returns a row (cross-section) from the SparseDataFrame as a Series
        object.

        Parameters
        ----------
        key : some index contained in the index

        Returns
        -------
        xs : Series
        """
        if axis == 1:
            data = self[key]
            return data

        i = self.index.get_loc(key)
        data = self.take([i]).get_values()[0]
        return Series(data, index=self.columns)

    #----------------------------------------------------------------------
    # Arithmetic-related methods 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:25,代码来源:frame.py

示例14: _join_index

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def _join_index(self, other, how, lsuffix, rsuffix):
        if isinstance(other, Series):
            if other.name is None:
                raise ValueError('Other Series must have a name')

            other = SparseDataFrame({other.name: other},
                                    default_fill_value=self._default_fill_value)

        join_index = self.index.join(other.index, how=how)

        this = self.reindex(join_index)
        other = other.reindex(join_index)

        this, other = this._maybe_rename_join(other, lsuffix, rsuffix)

        from pandas import concat
        return concat([this, other], axis=1, verify_integrity=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:frame.py

示例15: _iter_data

# 需要导入模块: from pandas.core import series [as 别名]
# 或者: from pandas.core.series import Series [as 别名]
def _iter_data(self):
        from pandas.core.frame import DataFrame
        if isinstance(self.data, (Series, np.ndarray)):
            yield self.label, np.asarray(self.data)
        elif isinstance(self.data, DataFrame):
            df = self.data

            if self.sort_columns:
                columns = com._try_sort(df.columns)
            else:
                columns = df.columns

            for col in columns:
                # # is this right?
                # empty = df[col].count() == 0
                # values = df[col].values if not empty else np.zeros(len(df))

                values = df[col].values
                yield col, values 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:plotting.py


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