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


Python common.is_period_dtype方法代码示例

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


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

示例1: test_is_period_dtype

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_period_dtype [as 别名]
def test_is_period_dtype():
    assert not com.is_period_dtype(object)
    assert not com.is_period_dtype([1, 2, 3])
    assert not com.is_period_dtype(pd.Period("2017-01-01"))

    assert com.is_period_dtype(PeriodDtype(freq="D"))
    assert com.is_period_dtype(pd.PeriodIndex([], freq="A")) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_common.py

示例2: _get_series_dispatcher

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_period_dtype [as 别名]
def _get_series_dispatcher(f, x):
    if is_period_dtype(x):
        return f.registry[PeriodType]
    elif is_datetime64_any_dtype(x):
        return f.registry[DatetimeType]

    raise TypeError("does not seem to be a period or datetime") 
开发者ID:machow,项目名称:siuba,代码行数:9,代码来源:datetime.py

示例3: __init__

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_period_dtype [as 别名]
def __init__(self, obj, orient, date_format, double_precision,
                 ensure_ascii, date_unit, index, default_handler=None):
        """
        Adds a `schema` attribute with the Table Schema, resets
        the index (can't do in caller, because the schema inference needs
        to know what the index is, forces orient to records, and forces
        date_format to 'iso'.
        """
        super(JSONTableWriter, self).__init__(
            obj, orient, date_format, double_precision, ensure_ascii,
            date_unit, index, default_handler=default_handler)

        if date_format != 'iso':
            msg = ("Trying to write with `orient='table'` and "
                   "`date_format='{fmt}'`. Table Schema requires dates "
                   "to be formatted with `date_format='iso'`"
                   .format(fmt=date_format))
            raise ValueError(msg)

        self.schema = build_table_schema(obj, index=self.index)

        # NotImplementd on a column MultiIndex
        if obj.ndim == 2 and isinstance(obj.columns, MultiIndex):
            raise NotImplementedError(
                "orient='table' is not supported for MultiIndex")

        # TODO: Do this timedelta properly in objToJSON.c See GH #15137
        if ((obj.ndim == 1) and (obj.name in set(obj.index.names)) or
                len(obj.columns & obj.index.names)):
            msg = "Overlapping names between the index and columns"
            raise ValueError(msg)

        obj = obj.copy()
        timedeltas = obj.select_dtypes(include=['timedelta']).columns
        if len(timedeltas):
            obj[timedeltas] = obj[timedeltas].applymap(
                lambda x: x.isoformat())
        # Convert PeriodIndex to datetimes before serialzing
        if is_period_dtype(obj.index):
            obj.index = obj.index.to_timestamp()

        # exclude index from obj if index=False
        if not self.index:
            self.obj = obj.reset_index(drop=True)
        else:
            self.obj = obj.reset_index(drop=False)
        self.date_format = 'iso'
        self.orient = 'records'
        self.index = index 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:51,代码来源:json.py

示例4: __init__

# 需要导入模块: from pandas.core.dtypes import common [as 别名]
# 或者: from pandas.core.dtypes.common import is_period_dtype [as 别名]
def __init__(self, obj, orient, date_format, double_precision,
                 ensure_ascii, date_unit, default_handler=None):
        """
        Adds a `schema` attribut with the Table Schema, resets
        the index (can't do in caller, because the schema inference needs
        to know what the index is, forces orient to records, and forces
        date_format to 'iso'.
        """
        super(JSONTableWriter, self).__init__(
            obj, orient, date_format, double_precision, ensure_ascii,
            date_unit, default_handler=default_handler)

        if date_format != 'iso':
            msg = ("Trying to write with `orient='table'` and "
                   "`date_format='{fmt}'`. Table Schema requires dates "
                   "to be formatted with `date_format='iso'`"
                   .format(fmt=date_format))
            raise ValueError(msg)

        self.schema = build_table_schema(obj)

        # NotImplementd on a column MultiIndex
        if obj.ndim == 2 and isinstance(obj.columns, MultiIndex):
            raise NotImplementedError(
                "orient='table' is not supported for MultiIndex")

        # TODO: Do this timedelta properly in objToJSON.c See GH #15137
        if ((obj.ndim == 1) and (obj.name in set(obj.index.names)) or
                len(obj.columns & obj.index.names)):
            msg = "Overlapping names between the index and columns"
            raise ValueError(msg)

        obj = obj.copy()
        timedeltas = obj.select_dtypes(include=['timedelta']).columns
        if len(timedeltas):
            obj[timedeltas] = obj[timedeltas].applymap(
                lambda x: x.isoformat())
        # Convert PeriodIndex to datetimes before serialzing
        if is_period_dtype(obj.index):
            obj.index = obj.index.to_timestamp()

        self.obj = obj.reset_index()
        self.date_format = 'iso'
        self.orient = 'records' 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:46,代码来源:json.py


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