本文整理匯總了Python中pandas.PeriodDtype方法的典型用法代碼示例。如果您正苦於以下問題:Python pandas.PeriodDtype方法的具體用法?Python pandas.PeriodDtype怎麽用?Python pandas.PeriodDtype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas
的用法示例。
在下文中一共展示了pandas.PeriodDtype方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: table_type
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import PeriodDtype [as 別名]
def table_type(df_column):
# Note - this only works with Pandas >= 1.0.0
if sys.version_info < (3, 0): # Pandas 1.0.0 does not support Python 2
return 'any'
if isinstance(df_column.dtype, pd.DatetimeTZDtype):
return 'datetime',
elif (isinstance(df_column.dtype, pd.StringDtype) or
isinstance(df_column.dtype, pd.BooleanDtype) or
isinstance(df_column.dtype, pd.CategoricalDtype) or
isinstance(df_column.dtype, pd.PeriodDtype)):
return 'text'
elif (isinstance(df_column.dtype, pd.SparseDtype) or
isinstance(df_column.dtype, pd.IntervalDtype) or
isinstance(df_column.dtype, pd.Int8Dtype) or
isinstance(df_column.dtype, pd.Int16Dtype) or
isinstance(df_column.dtype, pd.Int32Dtype) or
isinstance(df_column.dtype, pd.Int64Dtype)):
return 'numeric'
else:
return 'any'
示例2: test_pandas_extension_types
# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import PeriodDtype [as 別名]
def test_pandas_extension_types():
"""Test pandas extension data type happy path."""
# pylint: disable=no-member
test_params = [
(
pd.CategoricalDtype(),
pd.Series(["a", "a", "b", "b", "c", "c"], dtype="category"),
None
),
(
pd.DatetimeTZDtype(tz='UTC'),
pd.Series(
pd.date_range(start="20200101", end="20200301"),
dtype="datetime64[ns, utc]"
),
None
),
(pd.Int64Dtype(), pd.Series(range(10), dtype="Int64"), None),
(pd.StringDtype(), pd.Series(["foo", "bar", "baz"], dtype="string"), None),
(
pd.PeriodDtype(freq='D'),
pd.Series(pd.period_range('1/1/2019', '1/1/2020', freq='D')),
None
),
(
pd.SparseDtype("float"),
pd.Series(range(100)).where(
lambda s: s < 5, other=np.nan).astype("Sparse[float]"),
{"nullable": True},
),
(
pd.BooleanDtype(),
pd.Series([1, 0, 0, 1, 1], dtype="boolean"),
None
),
(
pd.IntervalDtype(subtype="int64"),
pd.Series(pd.IntervalIndex.from_breaks([0, 1, 2, 3, 4])),
None,
)
]
for dtype, data, series_kwargs in test_params:
series_kwargs = {} if series_kwargs is None else series_kwargs
series_schema = SeriesSchema(pandas_dtype=dtype, **series_kwargs)
assert isinstance(series_schema.validate(data), pd.Series)