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


Python common.is_float函数代码示例

本文整理汇总了Python中pandas.core.common.is_float函数的典型用法代码示例。如果您正苦于以下问题:Python is_float函数的具体用法?Python is_float怎么用?Python is_float使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _maybe_cast_slice_bound

    def _maybe_cast_slice_bound(self, label, side, kind):
        """
        If label is a string, cast it to timedelta according to resolution.


        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : string / None

        Returns
        -------
        label :  object

        """
        if isinstance(label, compat.string_types):
            parsed = _coerce_scalar_to_timedelta_type(label, box=True)
            lbound = parsed.round(parsed.resolution)
            if side == "left":
                return lbound
            else:
                return lbound + _resolution_map[parsed.resolution]() - Timedelta(1, "ns")
        elif is_integer(label) or is_float(label):
            self._invalid_indexer("slice", label)

        return label
开发者ID:arvindchari88,项目名称:newGitTest,代码行数:27,代码来源:tdi.py

示例2: convert

    def convert(values, unit, axis):
        def try_parse(values):
            try:
                return _dt_to_float_ordinal(tools.to_datetime(values))
            except Exception:
                return values

        if isinstance(values, (datetime, pydt.date)):
            return _dt_to_float_ordinal(values)
        elif isinstance(values, pydt.time):
            return dates.date2num(values)
        elif (com.is_integer(values) or com.is_float(values)):
            return values
        elif isinstance(values, compat.string_types):
            return try_parse(values)
        elif isinstance(values, (list, tuple, np.ndarray)):
            if not isinstance(values, np.ndarray):
                values = com._asarray_tuplesafe(values)

            if com.is_integer_dtype(values) or com.is_float_dtype(values):
                return values

            try:
                values = tools.to_datetime(values)
                if isinstance(values, Index):
                    values = values.map(_dt_to_float_ordinal)
                else:
                    values = [_dt_to_float_ordinal(x) for x in values]
            except Exception:
                pass

        return values
开发者ID:Acanthostega,项目名称:pandas,代码行数:32,代码来源:converter.py

示例3: _convert_scalar_indexer

    def _convert_scalar_indexer(self, key, kind=None):
        """
        we don't allow integer or float indexing on datetime-like when using
        loc

        Parameters
        ----------
        key : label of the slice bound
        kind : {'ix', 'loc', 'getitem', 'iloc'} or None
        """

        assert kind in ['ix', 'loc', 'getitem', 'iloc', None]

        # we don't allow integer/float indexing for loc
        # we don't allow float indexing for ix/getitem
        if lib.isscalar(key):
            is_int = is_integer(key)
            is_flt = is_float(key)
            if kind in ['loc'] and (is_int or is_flt):
                self._invalid_indexer('index', key)
            elif kind in ['ix', 'getitem'] and is_flt:
                self._invalid_indexer('index', key)

        return (super(DatetimeIndexOpsMixin, self)
                ._convert_scalar_indexer(key, kind=kind))
开发者ID:Jeevsy,项目名称:pandas,代码行数:25,代码来源:base.py

示例4: __new__

    def __new__(
        cls,
        data=None,
        ordinal=None,
        freq=None,
        start=None,
        end=None,
        periods=None,
        copy=False,
        name=None,
        tz=None,
        **kwargs
    ):

        freq = frequencies.get_standard_freq(freq)

        if periods is not None:
            if com.is_float(periods):
                periods = int(periods)
            elif not com.is_integer(periods):
                raise ValueError("Periods must be a number, got %s" % str(periods))

        if data is None:
            if ordinal is not None:
                data = np.asarray(ordinal, dtype=np.int64)
            else:
                data, freq = cls._generate_range(start, end, periods, freq, kwargs)
        else:
            ordinal, freq = cls._from_arraylike(data, freq, tz)
            data = np.array(ordinal, dtype=np.int64, copy=False)

        return cls._simple_new(data, name=name, freq=freq)
开发者ID:hrestrepo,项目名称:pandas,代码行数:32,代码来源:period.py

示例5: _convert_index

def _convert_index(index):
    inferred_type = lib.infer_dtype(index)

    # Let's assume the index is homogeneous
    values = np.asarray(index)

    if inferred_type == 'datetime64':
        converted = values.view('i8')
        return converted, 'datetime64', _tables().Int64Col()
    elif isinstance(values[0], datetime):
        converted = np.array([(time.mktime(v.timetuple()) +
                            v.microsecond / 1E6) for v in values],
                            dtype=np.float64)
        return converted, 'datetime', _tables().Time64Col()
    elif isinstance(values[0], date):
        converted = np.array([time.mktime(v.timetuple()) for v in values],
                            dtype=np.int32)
        return converted, 'date', _tables().Time32Col()
    elif isinstance(values[0], basestring):
        converted = np.array(list(values), dtype=np.str_)
        itemsize = converted.dtype.itemsize
        return converted, 'string', _tables().StringCol(itemsize)
    elif com.is_integer(values[0]):
        # take a guess for now, hope the values fit
        atom = _tables().Int64Col()
        return np.asarray(values, dtype=np.int64), 'integer', atom
    elif com.is_float(values[0]):
        atom = _tables().Float64Col()
        return np.asarray(values, dtype=np.float64), 'float', atom
    else: # pragma: no cover
        atom = _tables().ObjectAtom()
        return np.asarray(values, dtype='O'), 'object', atom
开发者ID:dhm116,项目名称:pandas,代码行数:32,代码来源:pytables.py

示例6: _convert_index

def _convert_index(index):
    # Let's assume the index is homogeneous
    values = np.asarray(index)

    if isinstance(values[0], (datetime, date)):
        if isinstance(values[0], datetime):
            kind = 'datetime'
        else:
            kind = 'date'
        converted = np.array([time.mktime(v.timetuple()) for v in values],
                             dtype=np.int64)
        return converted, kind, _tables().Time64Col()
    elif isinstance(values[0], basestring):
        converted = np.array(list(values), dtype=np.str_)
        itemsize = converted.dtype.itemsize
        return converted, 'string', _tables().StringCol(itemsize)
    elif com.is_integer(values[0]):
        # take a guess for now, hope the values fit
        atom = _tables().Int64Col()
        return np.asarray(values, dtype=np.int64), 'integer', atom
    elif com.is_float(values[0]):
        atom = _tables().Float64Col()
        return np.asarray(values, dtype=np.float64), 'float', atom
    else: # pragma: no cover
        atom = _tables().ObjectAtom()
        return np.asarray(values, dtype='O'), 'object', atom
开发者ID:xuanhan863,项目名称:pandas,代码行数:26,代码来源:pytables.py

示例7: _wrap_results

def _wrap_results(result, dtype):
    """ wrap our results if needed """

    if issubclass(dtype.type, np.datetime64):
        if not isinstance(result, np.ndarray):
            result = lib.Timestamp(result)
        else:
            result = result.view(dtype)
    elif issubclass(dtype.type, np.timedelta64):
        if not isinstance(result, np.ndarray):

            # this is a scalar timedelta result!
            # we have series convert then take the element (scalar)
            # as series will do the right thing in py3 (and deal with numpy
            # 1.6.2 bug in that it results dtype of timedelta64[us]
            from pandas import Series

            # coerce float to results
            if is_float(result):
                result = int(result)
            result = Series([result], dtype='timedelta64[ns]')
        else:
            result = result.view(dtype)

    return result
开发者ID:Barneyjm,项目名称:pandas,代码行数:25,代码来源:nanops.py

示例8: _maybe_cast_slice_bound

    def _maybe_cast_slice_bound(self, label, side, kind):
        """
        If label is a string or a datetime, cast it to Period.ordinal according to
        resolution.

        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : string / None

        Returns
        -------
        bound : Period or object

        Notes
        -----
        Value of `side` parameter should be validated in caller.

        """
        if isinstance(label, datetime):
            return Period(label, freq=self.freq)
        elif isinstance(label, compat.string_types):
            try:
                _, parsed, reso = parse_time_string(label, self.freq)
                bounds = self._parsed_string_to_bounds(reso, parsed)
                return bounds[0 if side == 'left' else 1]
            except Exception:
                raise KeyError(label)
        elif is_integer(label) or is_float(label):
            self._invalid_indexer('slice',label)

        return label
开发者ID:Arthurkorn,项目名称:pandas,代码行数:33,代码来源:period.py

示例9: _maybe_cast_slice_bound

    def _maybe_cast_slice_bound(self, label, side, kind):
        """
        If label is a string, cast it to timedelta according to resolution.


        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : {'ix', 'loc', 'getitem'}

        Returns
        -------
        label :  object

        """
        assert kind in ['ix', 'loc', 'getitem', None]

        if isinstance(label, compat.string_types):
            parsed = _coerce_scalar_to_timedelta_type(label, box=True)
            lbound = parsed.round(parsed.resolution)
            if side == 'left':
                return lbound
            else:
                return (lbound + to_offset(parsed.resolution) -
                        Timedelta(1, 'ns'))
        elif is_integer(label) or is_float(label):
            self._invalid_indexer('slice', label)

        return label
开发者ID:AbnerZheng,项目名称:pandas,代码行数:30,代码来源:tdi.py

示例10: _maybe_cast_slice_bound

    def _maybe_cast_slice_bound(self, label, side, kind):
        """
        This function should be overloaded in subclasses that allow non-trivial
        casting on label-slice bounds, e.g. datetime-like indices allowing
        strings containing formatted datetimes.

        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : string / None

        Returns
        -------
        label :  object

        Notes
        -----
        Value of `side` parameter should be validated in caller.

        """

        # we are a numeric index, so we accept
        # integer/floats directly
        if not (com.is_integer(label) or com.is_float(label)):
            self._invalid_indexer('slice', label)

        return label
开发者ID:alorenzo175,项目名称:pandas,代码行数:28,代码来源:numeric.py

示例11: __new__

    def __new__(cls, data=None, ordinal=None,
                freq=None, start=None, end=None, periods=None,
                copy=False, name=None,
                year=None, month=None, quarter=None, day=None,
                hour=None, minute=None, second=None):

        freq = _freq_mod.get_standard_freq(freq)

        if periods is not None:
            if com.is_float(periods):
                periods = int(periods)
            elif not com.is_integer(periods):
                raise ValueError('Periods must be a number, got %s' %
                                 str(periods))

        if data is None:
            if ordinal is not None:
                data = np.asarray(ordinal, dtype=np.int64)
            else:
                fields = [year, month, quarter, day, hour, minute, second]
                data, freq = cls._generate_range(start, end, periods,
                                                    freq, fields)
        else:
            ordinal, freq = cls._from_arraylike(data, freq)
            data = np.array(ordinal, dtype=np.int64, copy=False)

        subarr = data.view(cls)
        subarr.name = name
        subarr.freq = freq

        return subarr
开发者ID:MikeLindenau,项目名称:pandas,代码行数:31,代码来源:period.py

示例12: _format_label

def _format_label(x, precision=3):
    fmt_str = '%%.%dg' % precision
    if np.isinf(x):
        return str(x)
    elif com.is_float(x):
        frac, whole = np.modf(x)
        sgn = '-' if x < 0 else ''
        whole = abs(whole)
        if frac != 0.0:
            val = fmt_str % frac

            # rounded up or down
            if '.' not in val:
                if x < 0:
                    return '%d' % (-whole - 1)
                else:
                    return '%d' % (whole + 1)

            if 'e' in val:
                return _trim_zeros(fmt_str % x)
            else:
                val = _trim_zeros(val)
                if '.' in val:
                    return sgn + '.'.join(('%d' % whole, val.split('.')[1]))
                else:  # pragma: no cover
                    return sgn + '.'.join(('%d' % whole, val))
        else:
            return sgn + '%0.f' % whole
    else:
        return str(x)
开发者ID:ARF1,项目名称:pandas,代码行数:30,代码来源:tile.py

示例13: _get_string_slice

 def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
     freq = getattr(self, 'freqstr',
                    getattr(self, 'inferred_freq', None))
     if is_integer(key) or is_float(key):
         self._invalid_indexer('slice', key)
     loc = self._partial_td_slice(key, freq, use_lhs=use_lhs,
                                  use_rhs=use_rhs)
     return loc
开发者ID:AbnerZheng,项目名称:pandas,代码行数:8,代码来源:tdi.py

示例14: _ensure_numeric

def _ensure_numeric(x):
    if isinstance(x, np.ndarray):
        if x.dtype == np.object_:
            x = x.astype(np.float64)
    elif not (com.is_float(x) or com.is_integer(x)):
        try:
            x = float(x)
        except Exception:
            raise TypeError('Could not convert %s to numeric' % str(x))

    return x
开发者ID:X1mengYu,项目名称:pandas,代码行数:11,代码来源:nanops.py

示例15: _conv_value

def _conv_value(val):
    # Convert numpy types to Python types for the Excel writers.
    if com.is_integer(val):
        val = int(val)
    elif com.is_float(val):
        val = float(val)
    elif com.is_bool(val):
        val = bool(val)
    elif isinstance(val, Period):
        val = "%s" % val

    return val
开发者ID:Autodidact24,项目名称:pandas,代码行数:12,代码来源:excel.py


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