當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cudf.Series.from_categorical用法及代碼示例

用法:

classmethod Series.from_categorical(categorical, codes=None)

從 pandas.Categorical 創建

參數

categoricalpandas.Categorical

包含存儲在 pandas 分類中的數據。

codesarray-like,可選。

此分類的分類代碼。如果定義了codes,則使用它們而不是categorical.codes

返回

Series

一個 cudf 分類係列。

例子

>>> import cudf
>>> import pandas as pd
>>> pd_categorical = pd.Categorical(pd.Series(['a', 'b', 'c', 'a'], dtype='category'))
>>> pd_categorical
['a', 'b', 'c', 'a']
Categories (3, object): ['a', 'b', 'c']
>>> series = cudf.Series.from_categorical(pd_categorical)
>>> series
0    a
1    b
2    c
3    a
dtype: category
Categories (3, object): ['a', 'b', 'c']

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.Series.from_categorical。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。