hyb
2025-11-07 cadac0a99d87c53805a07f3b4ca7fd11e524fe4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
Ë
nñúhHJãó\—ddlmZddlmZddlmZmZddlZddlm    Z    m
Z
ddl Z ddl mZddlmZddlmZmZmZmZdd    lmZmZdd
lmZdd lmZdd lmZdd l m!Z!ddl"m#Z#m$Z$ddl%m&Z&e    rddl'm(Z(                            d                                            dd„Z)                    d                                            dd„Z*        d                            dd„Z+y)é)Ú annotations)Ú defaultdict)ÚHashableÚIterableN)Ú TYPE_CHECKINGÚcast)Úmissing)Ú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
󤇗ddlm}gd¢}    t|t«r—|€|j    |    ¬«Šnt |«s t d«‚||Šdˆfd„ }
|
|d«|
|d«t|t«rtj|g«}t|t«r‰jD cgc]} || ‘Œ    }} |€ ‰j}t|t«rtj|g«}n,t|t«r‰jD cgc]} || ‘Œ    }} ‰j|jk(rg} n*||j|d    ¬
«g} n|j    |    ¬ «g} t‰j«||«D],\} } }t!| d    | |||||¬ «}| j#|«Œ.|| d    ¬
«}|St!|||||||¬ «}|Scc} wcc} 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|«‰jdk(s-d|›dt|«›d‰jd›d}t|«‚yy)Néz Length 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   €úOH:\Change_password\venv_build\Lib\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)r3r4r5)r'Ústr)Úpandas.core.reshape.concatrÚ
isinstancerÚ select_dtypesr Ú    TypeErrorr6Ú    itertoolsÚcycleÚdictÚcolumnsr$ÚdropÚzipÚitemsÚ_get_dummies_1dÚappend)Údatar-r.r2r>r3r4r5rÚdtypes_to_encoder+ÚcolÚ with_dummiesÚpreÚsepÚdummyÚresultr)s                 @r*Ú get_dummiesrL,sñø€õf2â7Ðä$œ    Õ"à ˆ?Ø!×/Ñ/Ð8HÐ/ÓI‰NܘgÔ&ÜÐOÓPÐ Pà! '™]ˆNõ    .ñ    &˜(Ô#ِ*˜lÔ+ä fœcÔ "Ü—_‘_ f XÓ.ˆFÜ fœdÔ #Ø-;×-CÑ-CÖD cf˜S“kÐDˆFÐDà ˆ>Ø#×+Ñ+ˆFô j¤#Ô &Ü"Ÿ™¨*¨Ó6‰JÜ ˜
¤DÔ )Ø5C×5KÑ5KÖL¨c˜* S›/ÐLˆJÐLð × Ñ  4§:¡:Ò -à‰LØ Ð  ð!ŸI™I g°A˜IÓ6Ð7‰Lð!×.Ñ.Ð7GÐ.ÓHÐIˆLä  ×!5Ñ!5Ó!7¸ÀÓLò     '‰MˆCcä#ؐA‘ØØØ!ØØ%ØôˆEð × Ñ  Õ &ð     'ñ˜ ¨1Ô-ˆð €Mô!Ø Ø Ø Ø ØØ!Øô
ˆð €Mùò_EùòMs Â) GÄ
G c    ó|—ddlm}tt|d¬««\}}    |€¾t    |d«r²|j
}
t |
t«r|
jj
}
t |
t«rddl
} t| j««}nmt |
t«r(|
jtjur t!d«}n5t#j
t$«}n|€t#j
t$«}t!|«} t'| «r t)d«‚dd„} |st+|    «dk(r| |«S|j-«}|r:t+|    «||d    k(<|    j/t+|    «t"j0«}    |rt+|    «d
k(r| |«St+|    «}|€|    }nt3|    Dcgc]
}|›|›|›‘Œ c}«}t |t«r |j4}nd}|r't7|«rd}n!|t#j
t$«k(rd}nd }g}t+|«}t9t+|««Dcgc]}g‘Œ}}|d    k7}||}t#j:|«|}t=||«D]\}}||j?|«Œ|r
|d
d}|d
d}t=||«D]Z\}}tAt#jBt+|«|¬ «tE||«||¬ «}|j?t|||d¬««Œ\||d
d¬«St+|«|f}t | t"j
«r| }nt"j}t#jF||d¬«} d
| t#j:t+|««|f<|sd| |d    k(<|r| dd…d
d…f} |d
d}tI| ||| ¬«Scc}wcc}w)NrrF©Úcopyr5Úbooleanz1dtype=object is not a valid dtype for get_dummiescó|—t|t«r |j}ntt    |««}t |¬«S)N)Úindex)r8rrRrr#r)rDrRs  r*Úget_empty_framez(_get_dummies_1d.<locals>.get_empty_frames.€ä dœFÔ #Ø—J‘J‰Eä!¤# d£)Ó,ˆEܘuÔ%Ð%r,éÿÿÿÿr!g©r5)Ú sparse_indexÚ
fill_valuer5)rDrRr'rO)r0rOÚF)r$r5Úorder)rRr>r5)Úreturnr)%r7rrrÚhasattrr5r8rÚ
categoriesrÚpyarrowÚbool_rÚna_valueÚ
libmissingÚNArÚnpÚboolr r%r#rOÚinsertÚnanrrRr ÚrangeÚaranger@rCrÚonesr
Úzerosr)!rDr-r.r2r3r4r5rÚcodesÚlevelsÚ input_dtypeÚpaÚ_dtyperSÚnumber_of_colsÚ
dummy_colsÚlevelrRrWÚ sparse_seriesÚNÚ_Ú
sp_indicesÚmaskÚn_idxÚndxÚcoderFÚixsÚsarrr$Ú dummy_dtypeÚ    dummy_mats!                                 r*rBrBïsp€õ2ô,¬F°4¸eÔ,DÓEM€Eˆ6à €}œ  wÔ/Ø—j‘jˆ Ü kÔ#3Ô 4Ø%×0Ñ0×6Ñ6ˆKä k¤:Ô .Û  ä˜rŸx™x›zÓ*‰Eä {¤KÔ 0Ø×$Ñ$¬
¯ © Ñ5ä  Ó+‰Eä—H‘HœT“N‰EØ    ˆÜ—‘œ“ˆä ˜%Ó  €FävÔÜÐLÓMÐMó&ñ œ˜F›  qÒ(Ù˜tÓ$Ð$à J‰J‹L€EÙÜ  ›[ˆˆer‰kÑØ—‘œs 6›{¬B¯F©FÓ3ˆñ”c˜&“k QÒ&Ù˜tÓ$Ð$䘓[€Nà €~؉
äÈÖO¸u˜v˜h z l°5°'Ò:ÒOÓPˆ
ô$œÔØ—
‘
‰àˆâ ä ˜EÔ "؉JØ ”b—h‘hœt“nÒ $؉JàˆJàˆ Ü ‹IˆÜ.3´C¸
³OÓ.DÖ!E¨¢"Ð!Eˆ
Ð!Eؘ‰{ˆØd‘ ˆÜ—    ‘    ˜!“ ˜TÑ"ˆä˜U EÓ*ò    )‰IˆCØ tÑ × #Ñ # CÕ (ð    )ñ ð$ A B˜ˆJØ# A B˜ˆJܘJ¨
Ó3ò    W‰HˆCÜÜ—‘œ˜C›¨Ô.Ü% a¨Ó-Ø%Øô    ˆDð ×  Ñ  ¤¨T¸ÀSÈuÔ!UÕ Vð    Wñm¨!°%Ô8Ð8ôE“
˜NÐ*ˆä fœbŸh™hÔ 'Ø ‰KäŸ(™(ˆKÜ—H‘H 5° À3ÔGˆ    Ø23ˆ    ”"—)‘)œC ›JÓ'¨Ð.Ñ/áà%&ˆIe˜r‘kÑ "á à!¢! Q¡R %Ñ(ˆIØ# A B˜ˆJܘ¨%¸È6ÔRÐRùò}Pùò&"Fs Æ5N4È?    N9c    ó—ddlm}t|t«s!t    dt |«j ›«‚tt|j«j««}|j«rtd|j«›d«‚    |jdd¬«}tt«}|€t|j «|d <nt|t"«r_|j D]O}|j%|«d}t'|«t'|«k(rtd |›«‚||j)|«ŒQn!t    d t |«j ›«‚|¡t|t*«r=t'|«t'|«k(szdt'|«›dt'|«›d}    t|    «‚t|t,«r#t+t/||gt'|«z««}n!t    dt |«j ›«‚i}
|j1«D]ˆ\}} |€| j3«} n| Dcgc]}|t'||z«d
‘Œ} }|j4d
d
…| fj7d¬«} t| dkD«rtd| j«›«‚t| dk(«rbt|t*«r| j)||«ntd| j9«›«‚||j4d
d
…| f| dk(fd¬«}n|j4d
d
…| f}|j;| |j j<¬«}|jd¬«}|j j?|«}|jA|«jC|jD«|
|<Œ‹t|
«}|4|j j|j j<«|_|S#t$r t    d    «‚wxYwcc}w)a>
    Create a categorical ``DataFrame`` from a ``DataFrame`` of dummy variables.
 
    Inverts the operation performed by :func:`~pandas.get_dummies`.
 
    .. versionadded:: 1.5.0
 
    Parameters
    ----------
    data : DataFrame
        Data which contains dummy-coded variables in form of integer columns of
        1's and 0's.
    sep : str, default None
        Separator used in the column names of the dummy categories they are
        character indicating the separation of the categorical names from the prefixes.
        For example, if your column names are 'prefix_A' and 'prefix_B',
        you can strip the underscore by specifying sep='_'.
    default_category : None, Hashable or dict of Hashables, default None
        The default category is the implied category when a value has none of the
        listed categories specified with a one, i.e. if all dummies in a row are
        zero. Can be a single value for all variables or a dict directly mapping
        the default categories to a prefix of a variable.
 
    Returns
    -------
    DataFrame
        Categorical data decoded from the dummy input-data.
 
    Raises
    ------
    ValueError
        * When the input ``DataFrame`` ``data`` contains NA values.
        * When the input ``DataFrame`` ``data`` contains column names with separators
          that do not match the separator specified with ``sep``.
        * When a ``dict`` passed to ``default_category`` does not include an implied
          category for each prefix.
        * When a value in ``data`` has more than one category assigned to it.
        * When ``default_category=None`` and a value in ``data`` has no category
          assigned to it.
    TypeError
        * When the input ``data`` is not of type ``DataFrame``.
        * When the input ``DataFrame`` ``data`` contains non-dummy data.
        * When the passed ``sep`` is of a wrong data type.
        * When the passed ``default_category`` is of a wrong data type.
 
    See Also
    --------
    :func:`~pandas.get_dummies` : Convert ``Series`` or ``DataFrame`` to dummy codes.
    :class:`~pandas.Categorical` : Represent a categorical variable in classic.
 
    Notes
    -----
    The columns of the passed dummy data should only include 1's and 0's,
    or boolean values.
 
    Examples
    --------
    >>> df = pd.DataFrame({"a": [1, 0, 0, 1], "b": [0, 1, 0, 0],
    ...                    "c": [0, 0, 1, 0]})
 
    >>> df
       a  b  c
    0  1  0  0
    1  0  1  0
    2  0  0  1
    3  1  0  0
 
    >>> pd.from_dummies(df)
    0     a
    1     b
    2     c
    3     a
 
    >>> df = pd.DataFrame({"col1_a": [1, 0, 1], "col1_b": [0, 1, 0],
    ...                    "col2_a": [0, 1, 0], "col2_b": [1, 0, 0],
    ...                    "col2_c": [0, 0, 1]})
 
    >>> df
          col1_a  col1_b  col2_a  col2_b  col2_c
    0       1       0       0       1       0
    1       0       1       1       0       0
    2       1       0       0       0       1
 
    >>> pd.from_dummies(df, sep="_")
        col1    col2
    0    a       b
    1    b       a
    2    a       c
 
    >>> df = pd.DataFrame({"col1_a": [1, 0, 0], "col1_b": [0, 1, 0],
    ...                    "col2_a": [0, 1, 0], "col2_b": [1, 0, 0],
    ...                    "col2_c": [0, 0, 0]})
 
    >>> df
          col1_a  col1_b  col2_a  col2_b  col2_c
    0       1       0       0       1       0
    1       0       1       1       0       0
    2       0       0       0       0       0
 
    >>> pd.from_dummies(df, sep="_", default_category={"col1": "d", "col2": "e"})
        col1    col2
    0    a       b
    1    b       a
    2    d       e
    rrz>Expected 'data' to be a 'DataFrame'; Received 'data' of type: z.Dummy DataFrame contains NA value in column: 'ú'rPFrNz(Passed DataFrame contains non-dummy dataNÚz$Separator not specified for column: zFExpected 'sep' to be of type 'str' or 'None'; Received 'sep' of type: zLength of 'default_category' (r"ú)znExpected 'default_category' to be of type 'None', 'Hashable', or 'dict'; Received 'default_category' of type: r!r/zEDummy DataFrame contains multi-assignment(s); First instance in row: zEDummy DataFrame contains unassigned value(s); First instance in row: rU)#r7rr8rr:ÚtypeÚ__name__rrÚisnaÚanyr%ÚidxmaxÚastyperÚlistr>r6Úsplitr#rCr=rr@rArOÚlocÚsumÚidxminÚ_constructor_slicedr5Úget_indexer_forÚtakeÚset_axisrR)rDrIÚdefault_categoryrÚ col_isna_maskÚdata_to_decodeÚvariables_slicerFr-r(Úcat_dataÚ prefix_sliceÚcatsÚassignedÚ
data_sliceÚ
cats_arrayÚ true_valuesÚindexerrKs                   r*Ú from_dummiesrps€õ\2ä dœIÔ &Üð (Ü(,¨T«
×(;Ñ(;Ð'<ð >ó
ð    
ô
œ §¡£§¡Ó!2Ó3€Mà×ÑÔÜð Ø×$Ñ$Ó&Ð' qð *ó
ð    
ð DØŸ™ Y°U˜Ó;ˆô
"¤$Ó'€OØ
€{Ü" 4§<¡<Ó0ˆ˜ÒÜ    CœÔ    Ø!×)Ñ)ò    0ˆCØ—Y‘Y˜s“^ AÑ&ˆFܐ6‹{œc #›hÒ&Ü Ð#GÈÀuÐ!MÓNÐNØ ˜FÑ #× *Ñ *¨3Õ /ñ        0ô ð 'Ü'+¨C£y×'9Ñ'9Ð&:ð <ó
ð    
ð
Ð#Ü Ð&¬Ô -ÜÐ'Ó(¬C°Ó,@Ò@à4´SÐ9IÓ5JÐ4KðLä˜OÓ,Ð-¨Qð0ðô
! Ó)Ð)Ü Ð(¬(Ô 3Ü#ܐOÐ&6Ð%7¼#¸oÓ:NÑ%NÓOó Ñ ôð8ôÐ(Ó)×2Ñ2Ð3ð5óð ð€HØ /× 5Ñ 5Ó 7óIш Ø ˆ;Ø×$Ñ$Ó&‰Dà8DÖE°Cœ˜F S™LÓ)Ð+Ò,ÐEˆDÐEØ!×%Ñ%¢a¨ oÑ6×:Ñ:ÀÐ:ÓBˆÜ ˆx˜!‰|Ô Üð*Ø*2¯/©/Ó*;Ð)<ð>óð ô ˆx˜1‰}Ô ÜÐ*¬DÔ1Ø— ‘ Ð,¨VÑ4Õ5ä ð.Ø.6¯o©oÓ.?Ð-@ðBóðñ Ø×#Ñ#¢A | OÑ4°hÀ!±mÐDÈ1ô‰Jð(×+Ñ+ªA¨|¨OÑ<ˆJØ×-Ñ-¨d¸$¿,¹,×:LÑ:LÐ-ÓMˆ
à ×'Ñ'¨QÐ'Ó/ˆ Ø×$Ñ$×4Ñ4°[ÓAˆØ%Ÿ?™?¨7Ó3×<Ñ<¸T¿Z¹ZÓHˆÓð9Iô<xÓ  €FØ
€ØŸ™×.Ñ.¨t¯|©|×/AÑ/AÓBˆŒØ €MøôU òDÜÐBÓCÐCðDüòZFsÂO#È2O;Ï#O8)NrtFNFFN) r.z$str | Iterable[str] | dict[str, str]r2rcr3rcr4rcr5zNpDtype | NonerZr)rtFFFN)NN)rDrrIz
None | strr‘z%None | Hashable | dict[str, Hashable]rZr),Ú
__future__rÚ collectionsrÚcollections.abcrrr;ÚtypingrrÚnumpyrbÚ pandas._libsr    r`Úpandas._libs.sparser
Úpandas.core.dtypes.commonr r r rÚpandas.core.dtypes.dtypesrrÚpandas.core.arraysrÚpandas.core.arrays.categoricalrÚpandas.core.arrays.string_rÚpandas.core.framerÚpandas.core.indexes.apirrÚpandas.core.seriesrÚpandas._typingrrLrBr©r,r*ú<module>r¯sIðÝ"å#÷ó÷ó
å.Ý(÷ó÷ õ
+ÝBÝ2Ý'÷õ&áÝ&ð
Ø7:ØØ ØØØ ð@ð5ð@ðð    @ð ð @ðð@ð ð@ðó@ðL8;ØØØØ ð~Sð5ð~Sðð    ~Sð
ð ~Sð ð ~Sð ð~Sðó~SðFØ>BðKØ
ðKà    ðKð<ðKðô    Kr,