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


Python types.is_list_like方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def __init__(
            self,
            col,
            into,
            regex=r'([A-Za-z0-9]+)',
            remove=True,
            convert=False,
    ):
        if isinstance(regex, str):
            self.regex = re.compile(regex)
        elif hasattrs(regex, ('split', 'match')):
            self.regex = regex
        else:
            raise TypeError(
                "Unknown type `{}` used to describe a regular "
                "expression.".format(type(regex))
            )
        if not pdtypes.is_list_like(into):
            into = [into]

        self.col = col
        self.into = into
        self.regex = regex
        self.remove = remove
        self.convert = convert 
開發者ID:has2k1,項目名稱:plydata,代碼行數:27,代碼來源:tidy_verbs.py

示例2: name_like_string

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def name_like_string(name: Union[str, Tuple]) -> str:
    """
    Return the name-like strings from str or tuple of str

    Examples
    --------
    >>> name = 'abc'
    >>> name_like_string(name)
    'abc'

    >>> name = ('abc',)
    >>> name_like_string(name)
    'abc'

    >>> name = ('a', 'b', 'c')
    >>> name_like_string(name)
    '(a, b, c)'
    """
    if is_list_like(name):
        name = tuple([str(n) for n in name])
    else:
        name = (str(name),)
    return ("(%s)" % ", ".join(name)) if len(name) > 1 else name[0] 
開發者ID:databricks,項目名稱:koalas,代碼行數:25,代碼來源:utils.py

示例3: _validate_subset

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def _validate_subset(df, subset):
    if subset is None:
        return subset
    if not is_list_like(subset):
        subset = [subset]
    else:
        subset = list(subset)

    for s in subset:
        if s not in df.dtypes:
            raise KeyError(pd.Index([s]))

    return subset 
開發者ID:mars-project,項目名稱:mars,代碼行數:15,代碼來源:drop_duplicates.py

示例4: isin

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def isin(elements, values):
    # TODO(hetao): support more type combinations, for example, DataFrame.isin.
    if is_list_like(values):
        values = list(values)
    elif not isinstance(values, (SERIES_TYPE, TENSOR_TYPE, INDEX_TYPE)):
        raise TypeError('only list-like objects are allowed to be passed to isin(), '
                        'you passed a [{}]'.format(type(values)))
    if not isinstance(elements, SERIES_TYPE):  # pragma: no cover
        raise NotImplementedError('Unsupported parameter types: %s and %s' %
                                  (type(elements), type(values)))
    op = DataFrameIsin(values)
    return op(elements) 
開發者ID:mars-project,項目名稱:mars,代碼行數:14,代碼來源:isin.py

示例5: __call__

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def __call__(self, target: DataFrame, value):
        inputs = [target]
        if np.isscalar(value):
            value_dtype = np.array(value).dtype
        else:
            if isinstance(value, (pd.Series, SERIES_TYPE)):
                value = asseries(value)
                inputs.append(value)
                value_dtype = value.dtype
            elif is_list_like(value) or isinstance(value, TENSOR_TYPE):
                value = asseries(value, index=target.index)
                inputs.append(value)
                value_dtype = value.dtype
            else:  # pragma: no cover
                raise TypeError('Wrong value type, could be one of scalar, Series or tensor')

            if value.index_value.key != target.index_value.key:  # pragma: no cover
                raise NotImplementedError('Does not support setting value '
                                          'with different index for now')

        index_value = target.index_value
        dtypes = target.dtypes
        dtypes.loc[self._indexes] = value_dtype
        columns_value = parse_index(dtypes.index, store_data=True)
        ret = self.new_dataframe(inputs, shape=(target.shape[0], len(dtypes)),
                                 dtypes=dtypes, index_value=index_value,
                                 columns_value=columns_value)
        target.data = ret.data 
開發者ID:mars-project,項目名稱:mars,代碼行數:30,代碼來源:setitem.py

示例6: _handle_timelike_values

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def _handle_timelike_values(array_value_type, value, value_dtype, strict_date_types):
    if is_list_like(value):
        value = [pd.Timestamp(val).to_datetime64() for val in value]
    else:
        value = pd.Timestamp(value).to_datetime64()
    value_dtype = pd.Series(value).dtype
    return value, value_dtype 
開發者ID:JDASoftwareGroup,項目名稱:kartothek,代碼行數:9,代碼來源:_generic.py

示例7: is_2d

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def is_2d(x):
    return is_list_like(x) or is_slice(x) 
開發者ID:modin-project,項目名稱:modin,代碼行數:4,代碼來源:indexing.py

示例8: is_boolean_array

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def is_boolean_array(x):
    return is_list_like(x) and all(map(is_bool, x)) 
開發者ID:modin-project,項目名稱:modin,代碼行數:4,代碼來源:indexing.py

示例9: _compute_lookup

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def _compute_lookup(self, row_loc, col_loc):
        if is_list_like(row_loc) and len(row_loc) == 1:
            if (
                isinstance(self.qc.index.values[0], np.datetime64)
                and type(row_loc[0]) != np.datetime64
            ):
                row_loc = [pandas.to_datetime(row_loc[0])]

        if isinstance(row_loc, slice):
            row_lookup = self.qc.index.get_indexer_for(
                self.qc.index.to_series().loc[row_loc]
            )
        elif isinstance(self.qc.index, pandas.MultiIndex):
            row_lookup = self.qc.index.get_locs(row_loc)
        elif is_boolean_array(row_loc):
            # If passed in a list of booleans, we return the index of the true values
            row_lookup = [i for i, row_val in enumerate(row_loc) if row_val]
        else:
            row_lookup = self.qc.index.get_indexer_for(row_loc)
        if isinstance(col_loc, slice):
            col_lookup = self.qc.columns.get_indexer_for(
                self.qc.columns.to_series().loc[col_loc]
            )
        elif isinstance(self.qc.columns, pandas.MultiIndex):
            col_lookup = self.qc.columns.get_locs(col_loc)
        elif is_boolean_array(col_loc):
            # If passed in a list of booleans, we return the index of the true values
            col_lookup = [i for i, col_val in enumerate(col_loc) if col_val]
        else:
            col_lookup = self.qc.columns.get_indexer_for(col_loc)
        return row_lookup, col_lookup 
開發者ID:modin-project,項目名稱:modin,代碼行數:33,代碼來源:indexing.py

示例10: _check_dtypes

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def _check_dtypes(self, locator):
        is_int = is_integer(locator)
        is_int_slice = is_integer_slice(locator)
        is_int_list = is_list_like(locator) and all(map(is_integer, locator))
        is_bool_arr = is_boolean_array(locator)

        if not any([is_int, is_int_slice, is_int_list, is_bool_arr]):
            raise ValueError(_ILOC_INT_ONLY_ERROR) 
開發者ID:modin-project,項目名稱:modin,代碼行數:10,代碼來源:indexing.py

示例11: to_ipaddress

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def to_ipaddress(values):
    """Convert values to IPArray

    Parameters
    ----------
    values : int, str, bytes, or sequence of those

    Returns
    -------
    addresses : IPArray

    Examples
    --------
    Parse strings
    >>> to_ipaddress(['192.168.1.1',
    ...               '2001:0db8:85a3:0000:0000:8a2e:0370:7334'])
    <IPArray(['192.168.1.1', '0:8a2e:370:7334:2001:db8:85a3:0'])>

    Or integers
    >>> to_ipaddress([3232235777,
                      42540766452641154071740215577757643572])
    <IPArray(['192.168.1.1', '0:8a2e:370:7334:2001:db8:85a3:0'])>

    Or packed binary representations
    >>> to_ipaddress([b'\xc0\xa8\x01\x01',
                      b' \x01\r\xb8\x85\xa3\x00\x00\x00\x00\x8a.\x03ps4'])
    <IPArray(['192.168.1.1', '0:8a2e:370:7334:2001:db8:85a3:0'])>
    """
    from . import IPArray

    if not is_list_like(values):
        values = [values]

    return IPArray(_to_ip_array(values)) 
開發者ID:ContinuumIO,項目名稱:cyberpandas,代碼行數:36,代碼來源:parser.py

示例12: bar

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def bar(self, subset=None, axis=0, color='#d65f5f', width=100,
            align='left'):
        """
        Color the background ``color`` proptional to the values in each column.
        Excludes non-numeric data by default.

        Parameters
        ----------
        subset: IndexSlice, default None
            a valid slice for ``data`` to limit the style application to
        axis: int
        color: str or 2-tuple/list
            If a str is passed, the color is the same for both
            negative and positive numbers. If 2-tuple/list is used, the
            first element is the color_negative and the second is the
            color_positive (eg: ['#d65f5f', '#5fba7d'])
        width: float
            A number between 0 or 100. The largest value will cover ``width``
            percent of the cell's width
        align : {'left', 'zero',' mid'}, default 'left'
            - 'left' : the min value starts at the left of the cell
            - 'zero' : a value of zero is located at the center of the cell
            - 'mid' : the center of the cell is at (max-min)/2, or
              if values are all negative (positive) the zero is aligned
              at the right (left) of the cell

              .. versionadded:: 0.20.0

        Returns
        -------
        self : Styler
        """
        subset = _maybe_numeric_slice(self.data, subset)
        subset = _non_reducing_slice(subset)

        base = 'width: 10em; height: 80%;'

        if not(is_list_like(color)):
            color = [color, color]
        elif len(color) == 1:
            color = [color[0], color[0]]
        elif len(color) > 2:
            msg = ("Must pass `color` as string or a list-like"
                   " of length 2: [`color_negative`, `color_positive`]\n"
                   "(eg: color=['#d65f5f', '#5fba7d'])")
            raise ValueError(msg)

        if align == 'left':
            self.apply(self._bar_left, subset=subset, axis=axis, color=color,
                       width=width, base=base)
        elif align == 'zero':
            self.apply(self._bar_center_zero, subset=subset, axis=axis,
                       color=color, width=width, base=base)
        elif align == 'mid':
            self.apply(self._bar_center_mid, subset=subset, axis=axis,
                       color=color, width=width, base=base)
        else:
            msg = ("`align` must be one of {'left', 'zero',' mid'}")
            raise ValueError(msg)

        return self 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:63,代碼來源:style.py

示例13: isin

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def isin(self, values):
        """
        Check whether `values` are contained in Series.

        Return a boolean Series showing whether each element in the Series
        matches an element in the passed sequence of `values` exactly.

        Parameters
        ----------
        values : list or set
            The sequence of values to test.

        Returns
        -------
        isin : Series (bool dtype)

        Examples
        --------
        >>> s = ks.Series(['lama', 'cow', 'lama', 'beetle', 'lama',
        ...                'hippo'], name='animal')
        >>> s.isin(['cow', 'lama'])
        0     True
        1     True
        2     True
        3    False
        4     True
        5    False
        Name: animal, dtype: bool

        Passing a single string as ``s.isin('lama')`` will raise an error. Use
        a list of one element instead:

        >>> s.isin(['lama'])
        0     True
        1    False
        2     True
        3    False
        4     True
        5    False
        Name: animal, dtype: bool

        >>> s.rename("a").to_frame().set_index("a").index.isin(['lama'])
        Index([True, False, True, False, True, False], dtype='object', name='a')
        """
        if not is_list_like(values):
            raise TypeError(
                "only list-like objects are allowed to be passed"
                " to isin(), you passed a [{values_type}]".format(values_type=type(values).__name__)
            )

        return self._with_new_scol(self.spark.column.isin(list(values))).rename(self.name) 
開發者ID:databricks,項目名稱:koalas,代碼行數:53,代碼來源:base.py

示例14: __getitem__

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def __getitem__(self, key):
        if self._is_df:
            if not isinstance(key, tuple) or len(key) != 2:
                raise TypeError("Use DataFrame.at like .at[row_index, column_name]")
            row_sel, col_sel = key
        else:
            assert self._is_series, type(self._kdf_or_kser)
            if isinstance(key, tuple) and len(key) != 1:
                raise TypeError("Use Series.at like .at[row_index]")
            row_sel = key
            col_sel = self._kdf_or_kser._column_label

        if len(self._internal.index_map) == 1:
            if is_list_like(row_sel):
                raise ValueError("At based indexing on a single index can only have a single value")
            row_sel = (row_sel,)
        elif not isinstance(row_sel, tuple):
            raise ValueError("At based indexing on multi-index can only have tuple values")
        if not (
            isinstance(col_sel, str)
            or (isinstance(col_sel, tuple) and all(isinstance(col, str) for col in col_sel))
        ):
            raise ValueError("At based indexing on multi-index can only have tuple values")
        if isinstance(col_sel, str):
            col_sel = (col_sel,)

        cond = reduce(
            lambda x, y: x & y,
            [scol == row for scol, row in zip(self._internal.index_spark_columns, row_sel)],
        )
        pdf = (
            self._internal.spark_frame.drop(NATURAL_ORDER_COLUMN_NAME)
            .filter(cond)
            .select(self._internal.spark_column_for(col_sel))
            .toPandas()
        )

        if len(pdf) < 1:
            raise KeyError(name_like_string(row_sel))

        values = pdf.iloc[:, 0].values
        return (
            values
            if (len(row_sel) < len(self._internal.index_map) or len(values) > 1)
            else values[0]
        ) 
開發者ID:databricks,項目名稱:koalas,代碼行數:48,代碼來源:indexing.py

示例15: clip

# 需要導入模塊: from pandas.api import types [as 別名]
# 或者: from pandas.api.types import is_list_like [as 別名]
def clip(self, lower: Union[float, int] = None, upper: Union[float, int] = None) -> "Series":
        """
        Trim values at input threshold(s).

        Assigns values outside boundary to boundary values.

        Parameters
        ----------
        lower : float or int, default None
            Minimum threshold value. All values below this threshold will be set to it.
        upper : float or int, default None
            Maximum threshold value. All values above this threshold will be set to it.

        Returns
        -------
        Series
            Series with the values outside the clip boundaries replaced

        Examples
        --------
        >>> ks.Series([0, 2, 4]).clip(1, 3)
        0    1
        1    2
        2    3
        Name: 0, dtype: int64

        Notes
        -----
        One difference between this implementation and pandas is that running
        `pd.Series(['a', 'b']).clip(0, 1)` will crash with "TypeError: '<=' not supported between
        instances of 'str' and 'int'" while `ks.Series(['a', 'b']).clip(0, 1)` will output the
        original Series, simply ignoring the incompatible types.
        """
        if is_list_like(lower) or is_list_like(upper):
            raise ValueError(
                "List-like value are not supported for 'lower' and 'upper' at the " + "moment"
            )

        if lower is None and upper is None:
            return self

        if isinstance(self.spark.data_type, NumericType):
            scol = self.spark.column
            if lower is not None:
                scol = F.when(scol < lower, lower).otherwise(scol)
            if upper is not None:
                scol = F.when(scol > upper, upper).otherwise(scol)
            return self._with_new_scol(scol.alias(self._internal.data_spark_column_names[0]))
        else:
            return self 
開發者ID:databricks,項目名稱:koalas,代碼行數:52,代碼來源:series.py


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