Convert categorical variable into dummy/indicator variables. Data must have category dtype to infer result's ``columns``. Parameters ---------- data : Series, or DataFrame For Series, the dtype must be categorical. For DataFrame, at least one column must be cat
(
data,
prefix=None,
prefix_sep="_",
dummy_na=False,
columns=None,
sparse=False,
drop_first=False,
dtype=bool,
**kwargs,
)
| 10 | |
| 11 | |
| 12 | def get_dummies( |
| 13 | data, |
| 14 | prefix=None, |
| 15 | prefix_sep="_", |
| 16 | dummy_na=False, |
| 17 | columns=None, |
| 18 | sparse=False, |
| 19 | drop_first=False, |
| 20 | dtype=bool, |
| 21 | **kwargs, |
| 22 | ): |
| 23 | """ |
| 24 | Convert categorical variable into dummy/indicator variables. |
| 25 | |
| 26 | Data must have category dtype to infer result's ``columns``. |
| 27 | |
| 28 | Parameters |
| 29 | ---------- |
| 30 | data : Series, or DataFrame |
| 31 | For Series, the dtype must be categorical. |
| 32 | For DataFrame, at least one column must be categorical. |
| 33 | prefix : string, list of strings, or dict of strings, default None |
| 34 | String to append DataFrame column names. |
| 35 | Pass a list with length equal to the number of columns |
| 36 | when calling get_dummies on a DataFrame. Alternatively, `prefix` |
| 37 | can be a dictionary mapping column names to prefixes. |
| 38 | prefix_sep : string, default '_' |
| 39 | If appending prefix, separator/delimiter to use. Or pass a |
| 40 | list or dictionary as with `prefix.` |
| 41 | dummy_na : bool, default False |
| 42 | Add a column to indicate NaNs, if False NaNs are ignored. |
| 43 | columns : list-like, default None |
| 44 | Column names in the DataFrame to be encoded. |
| 45 | If `columns` is None then all the columns with |
| 46 | `category` dtype will be converted. |
| 47 | sparse : bool, default False |
| 48 | Whether the dummy columns should be sparse or not. Returns |
| 49 | SparseDataFrame if `data` is a Series or if all columns are included. |
| 50 | Otherwise returns a DataFrame with some SparseBlocks. |
| 51 | |
| 52 | .. versionadded:: 0.18.2 |
| 53 | |
| 54 | drop_first : bool, default False |
| 55 | Whether to get k-1 dummies out of k categorical levels by removing the |
| 56 | first level. |
| 57 | |
| 58 | dtype : dtype, default bool |
| 59 | Data type for new columns. Only a single dtype is allowed. |
| 60 | |
| 61 | .. versionadded:: 0.18.2 |
| 62 | |
| 63 | Returns |
| 64 | ------- |
| 65 | dummies : DataFrame |
| 66 | |
| 67 | Examples |
| 68 | -------- |
| 69 | Dask's version only works with Categorical data, as this is the only way to |
searching dependent graphs…