用法:
cudf.get_dummies(df, prefix=None, prefix_sep='_', dummy_na=False, columns=None, cats=None, sparse=False, drop_first=False, dtype='uint8')
返回一個數據幀,其列是
df
中所有列的一個熱編碼- df:array-like、係列或數據幀
獲取虛擬指標的數據。
- prefix:str、dict 或序列,可選
要附加的前綴。 str(應用常量前綴)、將列名映射到前綴的 dict 或要應用的前綴序列,其長度與列數相同。如果未提供,則默認為空字符串
- prefix_sep:str, dict, or sequence,可選,默認 ‘_’
附加前綴時使用的分隔符
- dummy_na:布爾值,可選
如果忽略 False Nones,則添加一列以指示 Nones。
- cats:字典,可選
將列名映射到表示該列類別的值序列的字典。如果未提供,則將其計算為列的唯一值。
- sparse:布爾值,可選
現在這是急流中的非函數論點。
- drop_first:布爾值,可選
現在這是急流中的非函數論點。
- columns:str 序列,可選
要編碼的列的名稱。如果未提供,將嘗試對所有列進行編碼。請注意,這與 pandas 默認行為不同,後者使用 dtype object 或 categorical 對所有列進行編碼
- dtype:str,可選
輸出數據類型,默認 ‘uint8’
參數:
例子:
>>> import cudf >>> df = cudf.DataFrame({"a": ["value1", "value2", None], "b": [0, 0, 0]}) >>> cudf.get_dummies(df) b a_value1 a_value2 0 0 1 0 1 0 0 1 2 0 0 0
>>> cudf.get_dummies(df, dummy_na=True) b a_None a_value1 a_value2 0 0 0 1 0 1 0 0 0 1 2 0 1 0 0
>>> import numpy as np >>> df = cudf.DataFrame({"a":cudf.Series([1, 2, np.nan, None], ... nan_as_null=False)}) >>> df a 0 1.0 1 2.0 2 NaN 3 <NA>
>>> cudf.get_dummies(df, dummy_na=True, columns=["a"]) a_1.0 a_2.0 a_nan a_null 0 1 0 0 0 1 0 1 0 0 2 0 0 1 0 3 0 0 0 1
>>> series = cudf.Series([1, 2, None, 2, 4]) >>> series 0 1 1 2 2 <NA> 3 2 4 4 dtype: int64 >>> cudf.get_dummies(series, dummy_na=True) null 1 2 4 0 0 1 0 0 1 0 0 1 0 2 1 0 0 0 3 0 0 1 0 4 0 0 0 1
相關用法
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python cudf.Series.ceil用法及代碼示例
- Python cudf.core.column.string.StringMethods.endswith用法及代碼示例
- Python cudf.Series.update用法及代碼示例
- Python cudf.DataFrame.mod用法及代碼示例
- Python cudf.DataFrame.isin用法及代碼示例
- Python cudf.core.column.string.StringMethods.title用法及代碼示例
- Python cudf.DataFrame.rmul用法及代碼示例
- Python cudf.Series.max用法及代碼示例
- Python cudf.DatetimeIndex.dayofweek用法及代碼示例
- Python cudf.DataFrame.apply用法及代碼示例
- Python cudf.core.column.string.StringMethods.contains用法及代碼示例
- Python cudf.core.column.string.StringMethods.rsplit用法及代碼示例
- Python cudf.DataFrame.exp用法及代碼示例
- Python cudf.Series.head用法及代碼示例
- Python cudf.DataFrame.drop用法及代碼示例
- Python cudf.core.column.string.StringMethods.zfill用法及代碼示例
- Python cudf.Series.reindex用法及代碼示例
- Python cudf.Series.interleave_columns用法及代碼示例
- Python cudf.core.series.DatetimeProperties.month用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.get_dummies。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。