本文整理汇总了Python中pandas.api.types.union_categoricals方法的典型用法代码示例。如果您正苦于以下问题:Python types.union_categoricals方法的具体用法?Python types.union_categoricals怎么用?Python types.union_categoricals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.api.types
的用法示例。
在下文中一共展示了types.union_categoricals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: concatenate
# 需要导入模块: from pandas.api import types [as 别名]
# 或者: from pandas.api.types import union_categoricals [as 别名]
def concatenate(cls, dfs):
"""
Concatenate Pandas DataFrames with saving 'category' dtype
Parameters
----------
dfs: list of DataFrames
Returns
-------
A Pandas DataFrame
"""
categoricals_columns = set.intersection(
*[set(df.select_dtypes("category").columns.tolist()) for df in dfs]
)
for col in categoricals_columns:
uc = union_categoricals([df[col] for df in dfs])
for df in dfs:
df[col] = pandas.Categorical(df[col], categories=uc.categories)
return pandas.concat(dfs)
示例2: union_categoricals
# 需要导入模块: from pandas.api import types [as 别名]
# 或者: from pandas.api.types import union_categoricals [as 别名]
def union_categoricals(to_union, sort_categories=False, ignore_order=False):
warnings.warn("pandas.types.concat.union_categoricals is "
"deprecated and will be removed in a future version.\n"
"use pandas.api.types.union_categoricals",
FutureWarning, stacklevel=2)
from pandas.api.types import union_categoricals
return union_categoricals(
to_union, sort_categories=sort_categories, ignore_order=ignore_order)