pandas.get_dummies
pandas 3.1.1 · General functions · function
Expand categorical values into indicator columns, one per category.
Call syntax
pd.get_dummies(…) Full signature
pd.get_dummies(
data,
prefix=None,
prefix_sep='_',
dummy_na=False,
columns=None,
sparse=False,
drop_first=False,
dtype=None,
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
data |
Required Positional or keyword |
array-like, Series, or DataFrame Provide the input data read, transformed, or stored by this call. |
prefix |
Optional Positional or keyword Default None |
str, list of str, or dict of str Add text before generated labels or test for a beginning substring. |
prefix_sep |
Optional Positional or keyword Default '_' |
str, list of str, or dict of str |
dummy_na |
Optional Positional or keyword Default False |
bool |
columns |
Optional Positional or keyword Default None |
list-like Supply column labels or control how columns are handled. |
sparse |
Optional Positional or keyword Default False |
bool |
drop_first |
Optional Positional or keyword Default False |
bool |
dtype |
Optional Positional or keyword Default None |
dtype Choose the data type for the input conversion or result. |
Returns
DataFrame