用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。