Sindbad~EG File Manager
�
MٜgJ � �P � d dl mZ d dlmZ d dlmZmZ d dlZd dlm Z m
Z
d dlZd dl
mZ d dlmZmZmZmZ d dlmZmZ d d lmZ d d
lmZ d dlmZ d dlmZ d d
lm Z m!Z! d dl"m#Z# e rd dl$m%Z% d dd�Z& d dd�Z' d dd�Z(y)� )�annotations)�defaultdict)�Hashable�IterableN)�
TYPE_CHECKING�cast)�IntIndex)�is_integer_dtype�is_list_like�is_object_dtype�pandas_dtype)�
ArrowDtype�CategoricalDtype)�SparseArray)�factorize_from_iterable)�StringDtype)� DataFrame)�Index�
default_index)�Series)�NpDtypec
� �� ddl m} g d�} t | t � �r�|�| j | �� �nt |� st
d� �| | �d�fd�}
|
|d� |
|d� t |t � rt j |g� }t |t � r�j D �cg c] }|| �� }}|��j }t |t � rt j |g� }n,t |t � r�j D �cg c] }|| �� }}�j | j k( rg }n*|�| j |d �
� g}n| j | �� g}t �j � ||� D ], \ }}
}t! |d |
|||||�� }|j# |� �. ||d �
� }|S t! | ||||||�
� }|S c c}w c c}w )a�
Convert categorical variable into dummy/indicator variables.
Each variable is converted in as many 0/1 variables as there are different
values. Columns in the output are each named after a value; if the input is
a DataFrame, the name of the original variable is prepended to the value.
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`, `string`, 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.
dtype : dtype, default bool
Data type for new columns. Only a single dtype is allowed.
Returns
-------
DataFrame
Dummy-coded data. If `data` contains other columns than the
dummy-coded one(s), these will be prepended, unaltered, to the result.
See Also
--------
Series.str.get_dummies : Convert Series of strings to dummy codes.
:func:`~pandas.from_dummies` : Convert dummy codes to categorical ``DataFrame``.
Notes
-----
Reference :ref:`the user guide <reshaping.dummies>` for more examples.
Examples
--------
>>> s = pd.Series(list('abca'))
>>> pd.get_dummies(s)
a b c
0 True False False
1 False True False
2 False False True
3 True False False
>>> s1 = ['a', 'b', np.nan]
>>> pd.get_dummies(s1)
a b
0 True False
1 False True
2 False False
>>> pd.get_dummies(s1, dummy_na=True)
a b NaN
0 True False False
1 False True False
2 False False True
>>> 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 True False False True False
1 2 False True True False False
2 3 True False False False True
>>> pd.get_dummies(pd.Series(list('abcaa')))
a b c
0 True False False
1 False True False
2 False False True
3 True False False
4 True False False
>>> pd.get_dummies(pd.Series(list('abcaa')), drop_first=True)
b c
0 False False
1 True False
2 False True
3 False False
4 False False
>>> 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
r ��concat)�object�string�category)�includez1Input must be a list-like for parameter `columns`c � �� t | � rIt | � �j d k( s-d|� dt | � � d�j d � d�}t |� �y y )N� zLength of 'z' (�9) did not match the length of the columns being encoded (z).)r �len�shape�
ValueError)�item�name�len_msg�data_to_encodes ��G/usr/local/lib/python3.12/site-packages/pandas/core/reshape/encoding.py� check_lenzget_dummies.<locals>.check_len� sl �� ��D�!��4�y�N�$8�$8��$;�;�%�d�V�3�s�4�y�k� :�*�0�0��3�4�B�8� �
%�W�-�-�
<� "� �prefix�
prefix_sepr ��axis)�exclude)r, r- �dummy_na�sparse�
drop_first�dtype)r2 r3 r4 )r&