def get_dummies(data, prefix=None, prefix_sep='<STR_LIT:_>', dummy_na=False,<EOL>columns=None, sparse=False, drop_first=False, dtype=None):
from pandas.core.reshape.concat import concat<EOL>from itertools import cycle<EOL>dtypes_to_encode = ['<STR_LIT:object>', '<STR_LIT>']<EOL>if isinstance(data, DataFrame):<EOL><INDENT>if columns is None:<EOL><INDENT>data_to_encode = data.select_dtypes(<EOL>include=dtypes_to_encode)<EOL><DEDENT>else:<EOL><INDENT>data_to_encode = data[columns]<EOL><DEDENT>def check_len(item, name):<EOL><INDENT>len_msg = ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>if is_list_like(item):<EOL><INDENT>if not len(item) == data_to_encode.shape[<NUM_LIT:1>]:<EOL><INDENT>len_msg = len_msg.format(name=name, len_item=len(item),<EOL>len_enc=data_to_encode.shape[<NUM_LIT:1>])<EOL>raise ValueError(len_msg)<EOL><DEDENT><DEDENT><DEDENT>check_len(prefix, '<STR_LIT>')<EOL>check_len(prefix_sep, '<STR_LIT>')<EOL>if isinstance(prefix, str):<EOL><INDENT>prefix = cycle([prefix])<EOL><DEDENT>if isinstance(prefix, dict):<EOL><INDENT>prefix = [prefix[col] for col in data_to_encode.columns]<EOL><DEDENT>if prefix is None:<EOL><INDENT>prefix = data_to_encode.columns<EOL><DEDENT>if isinstance(prefix_sep, str):<EOL><INDENT>prefix_sep = cycle([prefix_sep])<EOL><DEDENT>elif isinstance(prefix_sep, dict):<EOL><INDENT>prefix_sep = [prefix_sep[col] for col in data_to_encode.columns]<EOL><DEDENT>if data_to_encode.shape == data.shape:<EOL><INDENT>with_dummies = []<EOL><DEDENT>elif columns is not None:<EOL><INDENT>with_dummies = [data.drop(columns, axis=<NUM_LIT:1>)]<EOL><DEDENT>else:<EOL><INDENT>with_dummies = [data.select_dtypes(exclude=dtypes_to_encode)]<EOL><DEDENT>for (col, pre, sep) in zip(data_to_encode.iteritems(), prefix,<EOL>prefix_sep):<EOL><INDENT>dummy = _get_dummies_1d(col[<NUM_LIT:1>], prefix=pre, prefix_sep=sep,<EOL>dummy_na=dummy_na, sparse=sparse,<EOL>drop_first=drop_first, dtype=dtype)<EOL>with_dummies.append(dummy)<EOL><DEDENT>result = concat(with_dummies, axis=<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>result = _get_dummies_1d(data, prefix, prefix_sep, dummy_na,<EOL>sparse=sparse,<EOL>drop_first=drop_first,<EOL>dtype=dtype)<EOL><DEDENT>return result<EOL>
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.
prefix_sep : str, default '_'
    If appending prefix, separator/delimiter to use. Or pass a
    list or dictionary as with `prefix`.
dummy_na : bool, default False
    Add a column to indicate NaNs, if False NaNs are ignored.
columns : list-like, default None
    Column names in the DataFrame to be encoded.
    If `columns` is None then all the columns with
    `object` or `category` dtype will be converted.
sparse : bool, default False
    Whether the dummy-encoded columns should be backed by
    a :class:`SparseArray` (True) or a regular NumPy array (False).
drop_first : bool, default False
    Whether to get k-1 dummies out of k categorical levels by removing the
    first level.

    .. versionadded:: 0.18.0

dtype : dtype, default np.uint8
    Data type for new columns. Only a single dtype is allowed.

    .. versionadded:: 0.23.0

Returns
-------
DataFrame
    Dummy-coded data.

See Also
--------
Series.str.get_dummies : Convert Series to dummy codes.

Examples
--------
>>> s = pd.Series(list('abca'))

>>> pd.get_dummies(s)
   a  b  c
0  1  0  0
1  0  1  0
2  0  0  1
3  1  0  0

>>> s1 = ['a', 'b', np.nan]

>>> pd.get_dummies(s1)
   a  b
0  1  0
1  0  1
2  0  0

>>> pd.get_dummies(s1, dummy_na=True)
   a  b  NaN
0  1  0    0
1  0  1    0
2  0  0    1

>>> df = pd.DataFrame({'A': ['a', 'b', 'a'], 'B': ['b', 'a', 'c'],
...                    'C': [1, 2, 3]})

>>> 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

>>> 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

>>> pd.get_dummies(pd.Series(list('abcaa')), drop_first=True)
   b  c
0  0  0
1  1  0
2  0  1
3  0  0
4  0  0

>>> pd.get_dummies(pd.Series(list('abc')), dtype=float)
     a    b    c
0  1.0  0.0  0.0
1  0.0  1.0  0.0
2  0.0  0.0  1.0