modin.pandas.get_dummies

snowflake.snowpark.modin.pandas.general.get_dummies(data, prefix=None, prefix_sep='_', dummy_na=False, columns=None, sparse=False, drop_first=False, dtype=None)[source]

Convert categorical variable into dummy/indicator variables.

Parameters:
  • data (array-like, Series, or DataFrame) – Data of which to get dummy indicators.

  • prefix (str, list of str, or dict of str, default None) – String to append DataFrame column names. Pass a list with length equal to the number of columns when calling get_dummies on a DataFrame. Alternatively, prefix can be a dictionary mapping column names to prefixes. Only str, list of str and None is supported for this parameter.

  • prefix_sep (str, default '_') – If appending prefix, separator/delimiter to use.

  • dummy_na (bool, default False) – Add a column to indicate NaNs, if False NaNs are ignored. Only the value False is supported for this parameter.

  • columns (list-like, default None) – Column names in the DataFrame to be encoded. If columns is None then all the columns with string dtype will be converted.

  • sparse (bool, default False) – Whether the dummy-encoded columns should be backed by a SparseArray (True) or a regular NumPy array (False). This parameter is ignored.

  • drop_first (bool, default False) – Whether to get k-1 dummies out of k categorical levels by removing the first level. Only the value False is supported for this parameter.

  • dtype (dtype, default np.uint8) – Data type for new columns. Only the value None is supported for this parameter.

Returns:

Dummy-coded data.

Return type:

DataFrame

Examples

>>> s = pd.Series(list('abca'))
Copy
>>> pd.get_dummies(s)
   a  b  c
0  1  0  0
1  0  1  0
2  0  0  1
3  1  0  0
Copy
>>> df = pd.DataFrame({'A': ['a', 'b', 'a'], 'B': ['b', 'a', 'c'],
...                    'C': [1, 2, 3]})
Copy
>>> pd.get_dummies(df, prefix=['col1', 'col2'])
   C  col1_a  col1_b  col2_a  col2_b  col2_c
0  1       1       0       0       1       0
1  2       0       1       1       0       0
2  3       1       0       0       0       1
Copy
>>> pd.get_dummies(pd.Series(list('abcaa')))
   a  b  c
0  1  0  0
1  0  1  0
2  0  0  1
3  1  0  0
4  1  0  0
Copy