本文整理汇总了Python中pandas.Int32Dtype方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.Int32Dtype方法的具体用法?Python pandas.Int32Dtype怎么用?Python pandas.Int32Dtype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas
的用法示例。
在下文中一共展示了pandas.Int32Dtype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: table_type
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Int32Dtype [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: create_in_dtypes
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Int32Dtype [as 别名]
def create_in_dtypes():
"""
Create a dictionary of input data types.
This specifies the dtypes of the input columns, which is necessary for some
cases where, e.g., a column is always NaN.
Returns:
dict: mapping columns names to :mod:`pandas` data types.
"""
# These measurement codes are used by all four of our measurement variables
common_codes = (
"LME",
"Measured",
"Measured and Substitute",
"Other",
"Substitute",
"Undetermined",
"Unknown Code",
"",
)
co2_so2_cats = pd.CategoricalDtype(categories=common_codes, ordered=False)
nox_cats = pd.CategoricalDtype(
categories=common_codes + ("Calculated",), ordered=False
)
state_cats = pd.CategoricalDtype(
categories=pc.cems_states.keys(), ordered=False)
in_dtypes = {
"state": state_cats,
"plant_id_eia": "int32",
"unitid": pd.StringDtype(),
# "operating_datetime_utc": "datetime",
"operating_time_hours": "float32",
"gross_load_mw": "float32",
"steam_load_1000_lbs": "float32",
"so2_mass_lbs": "float32",
"so2_mass_measurement_code": co2_so2_cats,
"nox_rate_lbs_mmbtu": "float32",
"nox_rate_measurement_code": nox_cats,
"nox_mass_lbs": "float32",
"nox_mass_measurement_code": nox_cats,
"co2_mass_tons": "float32",
"co2_mass_measurement_code": co2_so2_cats,
"heat_content_mmbtu": "float32",
"facility_id": pd.Int32Dtype(),
"unit_id_epa": pd.Int32Dtype(),
}
return in_dtypes