本文整理匯總了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