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


Python lib.map_infer方法代碼示例

本文整理匯總了Python中pandas._libs.lib.map_infer方法的典型用法代碼示例。如果您正苦於以下問題:Python lib.map_infer方法的具體用法?Python lib.map_infer怎麽用?Python lib.map_infer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas._libs.lib的用法示例。


在下文中一共展示了lib.map_infer方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_values

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def get_values(self, dtype=None):
        """
        return object dtype as boxed values, such as Timestamps/Timedelta
        """
        if is_object_dtype(dtype):
            values = self.values

            if self.ndim > 1:
                values = values.ravel()

            values = lib.map_infer(values, self._box_func)

            if self.ndim > 1:
                values = values.reshape(self.values.shape)

            return values
        return self.values 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:blocks.py

示例2: _box_values

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def _box_values(self, values):
        """
        apply box func to passed values
        """
        return lib.map_infer(values, self._box_func) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:datetimelike.py

示例3: _map

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def _map(f, arr, na_mask=False, na_value=np.nan, dtype=object):
    if not len(arr):
        return np.ndarray(0, dtype=dtype)

    if isinstance(arr, ABCSeries):
        arr = arr.values
    if not isinstance(arr, np.ndarray):
        arr = np.asarray(arr, dtype=object)
    if na_mask:
        mask = isna(arr)
        try:
            convert = not all(mask)
            result = lib.map_infer_mask(arr, f, mask.view(np.uint8), convert)
        except (TypeError, AttributeError) as e:
            # Reraise the exception if callable `f` got wrong number of args.
            # The user may want to be warned by this, instead of getting NaN
            if compat.PY2:
                p_err = r'takes (no|(exactly|at (least|most)) ?\d+) arguments?'
            else:
                p_err = (r'((takes)|(missing)) (?(2)from \d+ to )?\d+ '
                         r'(?(3)required )positional arguments?')

            if len(e.args) >= 1 and re.search(p_err, e.args[0]):
                raise e

            def g(x):
                try:
                    return f(x)
                except (TypeError, AttributeError):
                    return na_value

            return _map(g, arr, dtype=dtype)
        if na_value is not np.nan:
            np.putmask(result, mask, na_value)
            if result.dtype == object:
                result = lib.maybe_convert_objects(result)
        return result
    else:
        return lib.map_infer(arr, f) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:41,代碼來源:strings.py

示例4: get_values

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def get_values(self, dtype=None):
        """
        return object dtype as boxed values, such as Timestamps/Timedelta
        """
        if is_object_dtype(dtype):
            return lib.map_infer(self.values.ravel(),
                                 self._box_func).reshape(self.values.shape)
        return self.values 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:10,代碼來源:internals.py

示例5: str_get_dummies

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def str_get_dummies(arr, sep='|'):
    """
    Split each string in the Series by sep and return a frame of
    dummy/indicator variables.

    Parameters
    ----------
    sep : string, default "|"
        String to split on.

    Returns
    -------
    dummies : DataFrame

    See Also
    --------
    get_dummies

    Examples
    --------
    >>> pd.Series(['a|b', 'a', 'a|c']).str.get_dummies()
       a  b  c
    0  1  1  0
    1  1  0  0
    2  1  0  1

    >>> pd.Series(['a|b', np.nan, 'a|c']).str.get_dummies()
       a  b  c
    0  1  1  0
    1  0  0  0
    2  1  0  1
    """
    arr = arr.fillna('')
    try:
        arr = sep + arr + sep
    except TypeError:
        arr = sep + arr.astype(str) + sep

    tags = set()
    for ts in arr.str.split(sep):
        tags.update(ts)
    tags = sorted(tags - {""})

    dummies = np.empty((len(arr), len(tags)), dtype=np.int64)

    for i, t in enumerate(tags):
        pat = sep + t + sep
        dummies[:, i] = lib.map_infer(arr.values, lambda x: pat in x)
    return dummies, tags 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:51,代碼來源:strings.py

示例6: _format_strings

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def _format_strings(self):
        if self.float_format is None:
            float_format = get_option("display.float_format")
            if float_format is None:
                fmt_str = ('{{x: .{prec:d}g}}'
                           .format(prec=get_option("display.precision")))
                float_format = lambda x: fmt_str.format(x=x)
        else:
            float_format = self.float_format

        formatter = (
            self.formatter if self.formatter is not None else
            (lambda x: pprint_thing(x, escape_chars=('\t', '\r', '\n'))))

        def _format(x):
            if self.na_rep is not None and is_scalar(x) and isna(x):
                if x is None:
                    return 'None'
                elif x is NaT:
                    return 'NaT'
                return self.na_rep
            elif isinstance(x, PandasObject):
                return u'{x}'.format(x=x)
            else:
                # object dtype
                return u'{x}'.format(x=formatter(x))

        vals = self.values
        if isinstance(vals, Index):
            vals = vals._values
        elif isinstance(vals, ABCSparseArray):
            vals = vals.values

        is_float_type = lib.map_infer(vals, is_float) & notna(vals)
        leading_space = self.leading_space
        if leading_space is None:
            leading_space = is_float_type.any()

        fmt_values = []
        for i, v in enumerate(vals):
            if not is_float_type[i] and leading_space:
                fmt_values.append(u' {v}'.format(v=_format(v)))
            elif is_float_type[i]:
                fmt_values.append(float_format(v))
            else:
                if leading_space is False:
                    # False specifically, so that the default is
                    # to include a space if we get here.
                    tpl = u'{v}'
                else:
                    tpl = u' {v}'
                fmt_values.append(tpl.format(v=_format(v)))

        return fmt_values 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:56,代碼來源:format.py

示例7: str_get_dummies

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def str_get_dummies(arr, sep='|'):
    """
    Split each string in the Series by sep and return a frame of
    dummy/indicator variables.

    Parameters
    ----------
    sep : string, default "|"
        String to split on.

    Returns
    -------
    dummies : DataFrame

    Examples
    --------
    >>> Series(['a|b', 'a', 'a|c']).str.get_dummies()
       a  b  c
    0  1  1  0
    1  1  0  0
    2  1  0  1

    >>> Series(['a|b', np.nan, 'a|c']).str.get_dummies()
       a  b  c
    0  1  1  0
    1  0  0  0
    2  1  0  1

    See Also
    --------
    pandas.get_dummies
    """
    arr = arr.fillna('')
    try:
        arr = sep + arr + sep
    except TypeError:
        arr = sep + arr.astype(str) + sep

    tags = set()
    for ts in arr.str.split(sep):
        tags.update(ts)
    tags = sorted(tags - set([""]))

    dummies = np.empty((len(arr), len(tags)), dtype=np.int64)

    for i, t in enumerate(tags):
        pat = sep + t + sep
        dummies[:, i] = lib.map_infer(arr.values, lambda x: pat in x)
    return dummies, tags 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:51,代碼來源:strings.py

示例8: _convert_to_ndarrays

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
                             converters=None, dtypes=None):
        result = {}
        for c, values in compat.iteritems(dct):
            conv_f = None if converters is None else converters.get(c, None)
            if isinstance(dtypes, dict):
                cast_type = dtypes.get(c, None)
            else:
                # single dtype or None
                cast_type = dtypes

            if self.na_filter:
                col_na_values, col_na_fvalues = _get_na_values(
                    c, na_values, na_fvalues, self.keep_default_na)
            else:
                col_na_values, col_na_fvalues = set(), set()

            if conv_f is not None:
                # conv_f applied to data before inference
                if cast_type is not None:
                    warnings.warn(("Both a converter and dtype were specified "
                                   "for column {0} - only the converter will "
                                   "be used").format(c), ParserWarning,
                                  stacklevel=7)

                try:
                    values = lib.map_infer(values, conv_f)
                except ValueError:
                    mask = algorithms.isin(
                        values, list(na_values)).view(np.uint8)
                    values = lib.map_infer_mask(values, conv_f, mask)

                cvals, na_count = self._infer_types(
                    values, set(col_na_values) | col_na_fvalues,
                    try_num_bool=False)
            else:
                # skip inference if specified dtype is object
                try_num_bool = not (cast_type and is_string_dtype(cast_type))

                # general type inference and conversion
                cvals, na_count = self._infer_types(
                    values, set(col_na_values) | col_na_fvalues,
                    try_num_bool)

                # type specified in dtype param
                if cast_type and not is_dtype_equal(cvals, cast_type):
                    cvals = self._cast_types(cvals, cast_type, c)

            result[c] = cvals
            if verbose and na_count:
                print('Filled %d NA values in column %s' % (na_count, str(c)))
        return result 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:54,代碼來源:parsers.py

示例9: _format_strings

# 需要導入模塊: from pandas._libs import lib [as 別名]
# 或者: from pandas._libs.lib import map_infer [as 別名]
def _format_strings(self):
        if self.float_format is None:
            float_format = get_option("display.float_format")
            if float_format is None:
                fmt_str = ('{{x: .{prec:d}g}}'
                           .format(prec=get_option("display.precision")))
                float_format = lambda x: fmt_str.format(x=x)
        else:
            float_format = self.float_format

        formatter = (
            self.formatter if self.formatter is not None else
            (lambda x: pprint_thing(x, escape_chars=('\t', '\r', '\n'))))

        def _format(x):
            if self.na_rep is not None and lib.checknull(x):
                if x is None:
                    return 'None'
                elif x is pd.NaT:
                    return 'NaT'
                return self.na_rep
            elif isinstance(x, PandasObject):
                return u'{x}'.format(x=x)
            else:
                # object dtype
                return u'{x}'.format(x=formatter(x))

        vals = self.values
        if isinstance(vals, Index):
            vals = vals._values
        elif isinstance(vals, ABCSparseArray):
            vals = vals.values

        is_float_type = lib.map_infer(vals, is_float) & notna(vals)
        leading_space = is_float_type.any()

        fmt_values = []
        for i, v in enumerate(vals):
            if not is_float_type[i] and leading_space:
                fmt_values.append(u' {v}'.format(v=_format(v)))
            elif is_float_type[i]:
                fmt_values.append(float_format(v))
            else:
                fmt_values.append(u' {v}'.format(v=_format(v)))

        return fmt_values 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:48,代碼來源:format.py


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