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