vDataFrame.get_dummies

In [ ]:
vDataFrame.get_dummies(columns: list = [],
                       max_cardinality: int = 12, 
                       prefix_sep: str = "_", 
                       drop_first: bool = True, 
                       use_numbers_as_suffix: bool = False)

Encodes the vcolumns with the one-hot encoding algorithm.

Parameters

Name Type Optional Description
columns
list
List of the vcolumns to use to train the one-hot encoding model. If empty, only the vcolumns having a cardinality lesser than 'max_cardinality' will be used.
max_cardinality
int
Cardinality threshold to determine if the vcolumn will be taken into account during the encoding. This parameter is used only if the parameter 'columns' is empty.
prefix_sep
str
Prefix delimitor of the dummies.
drop_first
bool
Drops the first dummy to avoid the creation of correlated features.
use_numbers_as_suffix
bool
Uses numbers as suffix instead of the vcolumns categories.

Returns

vDataFrame : self

Example

In [7]:
from verticapy import vDataFrame
churn = vDataFrame("public.churn")
churn = churn.select(["InternetService", "PaymentMethod", "gender", "Contract", "churn"])
display(churn)
Abc
InternetService
Varchar(20)
Abc
PaymentMethod
Varchar(30)
Abc
gender
Varchar(6)
Abc
Contract
Varchar(20)
Abc
Churn
Varchar(3)
1DSLMailed checkFemaleOne yearNo
2DSLMailed checkMaleMonth-to-monthNo
3Fiber opticElectronic checkMaleMonth-to-monthYes
4Fiber opticElectronic checkMaleMonth-to-monthYes
5Fiber opticMailed checkFemaleMonth-to-monthYes
6DSLCredit card (automatic)FemaleMonth-to-monthNo
7Fiber opticBank transfer (automatic)FemaleTwo yearNo
8Fiber opticCredit card (automatic)MaleTwo yearNo
9DSLElectronic checkFemaleMonth-to-monthNo
10DSLMailed checkFemaleTwo yearNo
11DSLCredit card (automatic)MaleTwo yearNo
12Fiber opticCredit card (automatic)FemaleTwo yearNo
13Fiber opticElectronic checkFemaleMonth-to-monthNo
14Fiber opticBank transfer (automatic)FemaleTwo yearNo
15DSLBank transfer (automatic)FemaleTwo yearNo
16Fiber opticCredit card (automatic)FemaleTwo yearNo
17DSLMailed checkFemaleOne yearNo
18Fiber opticElectronic checkFemaleMonth-to-monthNo
19DSLCredit card (automatic)MaleOne yearYes
20DSLElectronic checkMaleMonth-to-monthYes
21NoElectronic checkFemaleOne yearNo
22Fiber opticElectronic checkFemaleMonth-to-monthYes
23Fiber opticElectronic checkFemaleMonth-to-monthNo
24NoMailed checkFemaleMonth-to-monthNo
25NoMailed checkFemaleMonth-to-monthYes
26DSLBank transfer (automatic)FemaleMonth-to-monthYes
27Fiber opticBank transfer (automatic)FemaleOne yearNo
28NoCredit card (automatic)MaleTwo yearNo
29NoBank transfer (automatic)MaleOne yearNo
30NoBank transfer (automatic)FemaleTwo yearNo
31Fiber opticCredit card (automatic)MaleOne yearNo
32NoBank transfer (automatic)FemaleOne yearNo
33Fiber opticBank transfer (automatic)MaleOne yearNo
34NoElectronic checkFemaleOne yearNo
35DSLCredit card (automatic)MaleTwo yearNo
36NoElectronic checkFemaleTwo yearNo
37Fiber opticBank transfer (automatic)FemaleMonth-to-monthNo
38Fiber opticElectronic checkFemaleMonth-to-monthNo
39NoBank transfer (automatic)FemaleTwo yearNo
40Fiber opticBank transfer (automatic)MaleMonth-to-monthNo
41DSLElectronic checkMaleMonth-to-monthYes
42DSLMailed checkFemaleOne yearNo
43NoCredit card (automatic)MaleTwo yearNo
44DSLBank transfer (automatic)MaleOne yearNo
45DSLMailed checkMaleMonth-to-monthNo
46DSLBank transfer (automatic)MaleTwo yearNo
47DSLCredit card (automatic)FemaleOne yearNo
48Fiber opticElectronic checkFemaleOne yearNo
49DSLMailed checkMaleMonth-to-monthNo
50Fiber opticElectronic checkMaleMonth-to-monthNo
51DSLElectronic checkMaleOne yearNo
52Fiber opticCredit card (automatic)FemaleMonth-to-monthNo
53Fiber opticElectronic checkFemaleMonth-to-monthNo
54Fiber opticCredit card (automatic)MaleMonth-to-monthYes
55Fiber opticElectronic checkFemaleMonth-to-monthYes
56DSLElectronic checkFemaleMonth-to-monthNo
57DSLMailed checkMaleMonth-to-monthNo
58NoElectronic checkMaleMonth-to-monthNo
59Fiber opticElectronic checkMaleOne yearNo
60Fiber opticBank transfer (automatic)FemaleOne yearNo
61DSLCredit card (automatic)MaleOne yearNo
62DSLBank transfer (automatic)MaleMonth-to-monthNo
63Fiber opticElectronic checkFemaleTwo yearNo
64NoElectronic checkMaleMonth-to-monthYes
65Fiber opticElectronic checkMaleMonth-to-monthYes
66Fiber opticMailed checkMaleMonth-to-monthNo
67Fiber opticBank transfer (automatic)MaleMonth-to-monthNo
68DSLElectronic checkMaleOne yearYes
69DSLBank transfer (automatic)FemaleTwo yearNo
70Fiber opticElectronic checkFemaleMonth-to-monthNo
71NoBank transfer (automatic)FemaleMonth-to-monthNo
72Fiber opticElectronic checkMaleMonth-to-monthYes
73DSLBank transfer (automatic)MaleMonth-to-monthYes
74Fiber opticCredit card (automatic)FemaleMonth-to-monthNo
75DSLMailed checkMaleOne yearNo
76Fiber opticElectronic checkFemaleMonth-to-monthYes
77DSLMailed checkFemaleTwo yearNo
78Fiber opticElectronic checkMaleMonth-to-monthYes
79DSLMailed checkFemaleMonth-to-monthNo
80Fiber opticElectronic checkMaleMonth-to-monthNo
81NoBank transfer (automatic)MaleOne yearNo
82Fiber opticCredit card (automatic)MaleMonth-to-monthNo
83Fiber opticElectronic checkFemaleMonth-to-monthYes
84DSLBank transfer (automatic)FemaleOne yearNo
85Fiber opticBank transfer (automatic)FemaleMonth-to-monthYes
86Fiber opticElectronic checkMaleTwo yearNo
87Fiber opticMailed checkFemaleMonth-to-monthYes
88NoMailed checkFemaleMonth-to-monthYes
89Fiber opticElectronic checkFemaleMonth-to-monthNo
90Fiber opticBank transfer (automatic)FemaleMonth-to-monthNo
91NoElectronic checkMaleMonth-to-monthNo
92Fiber opticElectronic checkFemaleMonth-to-monthNo
93Fiber opticBank transfer (automatic)MaleMonth-to-monthYes
94Fiber opticMailed checkFemaleMonth-to-monthYes
95DSLElectronic checkMaleMonth-to-monthYes
96Fiber opticElectronic checkFemaleTwo yearNo
97NoBank transfer (automatic)FemaleTwo yearNo
98Fiber opticElectronic checkFemaleMonth-to-monthNo
99NoCredit card (automatic)MaleTwo yearNo
100Fiber opticBank transfer (automatic)MaleMonth-to-monthNo
Rows: 1-100 of 7032 | Columns: 5
In [8]:
churn.get_dummies()
Abc
InternetService
Varchar(20)
Abc
PaymentMethod
Varchar(30)
Abc
gender
Varchar(6)
Abc
Contract
Varchar(20)
Abc
Churn
Varchar(3)
123
InternetService_DSL
Bool
123
InternetService_Fiber_optic
Bool
123
Bool
123
Bool
123
PaymentMethod_Electronic_check
Bool
123
gender_Female
Bool
123
Contract_Month-to-month
Bool
123
Contract_One_year
Bool
123
Churn_No
Bool
1DSLMailed checkFemaleOne yearNo1001011
2DSLMailed checkMaleMonth-to-monthNo1000101
3Fiber opticElectronic checkMaleMonth-to-monthYes0110100
4Fiber opticElectronic checkMaleMonth-to-monthYes0110100
5Fiber opticMailed checkFemaleMonth-to-monthYes0101100
6DSLCredit card (automatic)FemaleMonth-to-monthNo1001101
7Fiber opticBank transfer (automatic)FemaleTwo yearNo0101001
8Fiber opticCredit card (automatic)MaleTwo yearNo0100001
9DSLElectronic checkFemaleMonth-to-monthNo1011101
10DSLMailed checkFemaleTwo yearNo1001001
11DSLCredit card (automatic)MaleTwo yearNo1000001
12Fiber opticCredit card (automatic)FemaleTwo yearNo0101001
13Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
14Fiber opticBank transfer (automatic)FemaleTwo yearNo0101001
15DSLBank transfer (automatic)FemaleTwo yearNo1001001
16Fiber opticCredit card (automatic)FemaleTwo yearNo0101001
17DSLMailed checkFemaleOne yearNo1001011
18Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
19DSLCredit card (automatic)MaleOne yearYes1000010
20DSLElectronic checkMaleMonth-to-monthYes1010100
21NoElectronic checkFemaleOne yearNo0011011
22Fiber opticElectronic checkFemaleMonth-to-monthYes0111100
23Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
24NoMailed checkFemaleMonth-to-monthNo0001101
25NoMailed checkFemaleMonth-to-monthYes0001100
26DSLBank transfer (automatic)FemaleMonth-to-monthYes1001100
27Fiber opticBank transfer (automatic)FemaleOne yearNo0101011
28NoCredit card (automatic)MaleTwo yearNo0000001
29NoBank transfer (automatic)MaleOne yearNo0000011
30NoBank transfer (automatic)FemaleTwo yearNo0001001
31Fiber opticCredit card (automatic)MaleOne yearNo0100011
32NoBank transfer (automatic)FemaleOne yearNo0001011
33Fiber opticBank transfer (automatic)MaleOne yearNo0100011
34NoElectronic checkFemaleOne yearNo0011011
35DSLCredit card (automatic)MaleTwo yearNo1000001
36NoElectronic checkFemaleTwo yearNo0011001
37Fiber opticBank transfer (automatic)FemaleMonth-to-monthNo0101101
38Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
39NoBank transfer (automatic)FemaleTwo yearNo0001001
40Fiber opticBank transfer (automatic)MaleMonth-to-monthNo0100101
41DSLElectronic checkMaleMonth-to-monthYes1010100
42DSLMailed checkFemaleOne yearNo1001011
43NoCredit card (automatic)MaleTwo yearNo0000001
44DSLBank transfer (automatic)MaleOne yearNo1000011
45DSLMailed checkMaleMonth-to-monthNo1000101
46DSLBank transfer (automatic)MaleTwo yearNo1000001
47DSLCredit card (automatic)FemaleOne yearNo1001011
48Fiber opticElectronic checkFemaleOne yearNo0111011
49DSLMailed checkMaleMonth-to-monthNo1000101
50Fiber opticElectronic checkMaleMonth-to-monthNo0110101
51DSLElectronic checkMaleOne yearNo1010011
52Fiber opticCredit card (automatic)FemaleMonth-to-monthNo0101101
53Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
54Fiber opticCredit card (automatic)MaleMonth-to-monthYes0100100
55Fiber opticElectronic checkFemaleMonth-to-monthYes0111100
56DSLElectronic checkFemaleMonth-to-monthNo1011101
57DSLMailed checkMaleMonth-to-monthNo1000101
58NoElectronic checkMaleMonth-to-monthNo0010101
59Fiber opticElectronic checkMaleOne yearNo0110011
60Fiber opticBank transfer (automatic)FemaleOne yearNo0101011
61DSLCredit card (automatic)MaleOne yearNo1000011
62DSLBank transfer (automatic)MaleMonth-to-monthNo1000101
63Fiber opticElectronic checkFemaleTwo yearNo0111001
64NoElectronic checkMaleMonth-to-monthYes0010100
65Fiber opticElectronic checkMaleMonth-to-monthYes0110100
66Fiber opticMailed checkMaleMonth-to-monthNo0100101
67Fiber opticBank transfer (automatic)MaleMonth-to-monthNo0100101
68DSLElectronic checkMaleOne yearYes1010010
69DSLBank transfer (automatic)FemaleTwo yearNo1001001
70Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
71NoBank transfer (automatic)FemaleMonth-to-monthNo0001101
72Fiber opticElectronic checkMaleMonth-to-monthYes0110100
73DSLBank transfer (automatic)MaleMonth-to-monthYes1000100
74Fiber opticCredit card (automatic)FemaleMonth-to-monthNo0101101
75DSLMailed checkMaleOne yearNo1000011
76Fiber opticElectronic checkFemaleMonth-to-monthYes0111100
77DSLMailed checkFemaleTwo yearNo1001001
78Fiber opticElectronic checkMaleMonth-to-monthYes0110100
79DSLMailed checkFemaleMonth-to-monthNo1001101
80Fiber opticElectronic checkMaleMonth-to-monthNo0110101
81NoBank transfer (automatic)MaleOne yearNo0000011
82Fiber opticCredit card (automatic)MaleMonth-to-monthNo0100101
83Fiber opticElectronic checkFemaleMonth-to-monthYes0111100
84DSLBank transfer (automatic)FemaleOne yearNo1001011
85Fiber opticBank transfer (automatic)FemaleMonth-to-monthYes0101100
86Fiber opticElectronic checkMaleTwo yearNo0110001
87Fiber opticMailed checkFemaleMonth-to-monthYes0101100
88NoMailed checkFemaleMonth-to-monthYes0001100
89Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
90Fiber opticBank transfer (automatic)FemaleMonth-to-monthNo0101101
91NoElectronic checkMaleMonth-to-monthNo0010101
92Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
93Fiber opticBank transfer (automatic)MaleMonth-to-monthYes0100100
94Fiber opticMailed checkFemaleMonth-to-monthYes0101100
95DSLElectronic checkMaleMonth-to-monthYes1010100
96Fiber opticElectronic checkFemaleTwo yearNo0111001
97NoBank transfer (automatic)FemaleTwo yearNo0001001
98Fiber opticElectronic checkFemaleMonth-to-monthNo0111101
99NoCredit card (automatic)MaleTwo yearNo0000001
100Fiber opticBank transfer (automatic)MaleMonth-to-monthNo0100101
Out[8]:
Rows: 1-100 of 7032 | Columns: 14
In [9]:
# Number as suffix
churn.get_dummies(use_numbers_as_suffix = True)
Abc
InternetService
Varchar(20)
Abc
PaymentMethod
Varchar(30)
Abc
gender
Varchar(6)
Abc
Contract
Varchar(20)
Abc
Churn
Varchar(3)
123
InternetService_DSL
Bool
123
InternetService_Fiber_optic
Bool
123
Bool
123
Bool
123
PaymentMethod_Electronic_check
Bool
123
gender_Female
Bool
123
Contract_Month-to-month
Bool
123
Contract_One_year
Bool
123
Churn_No
Bool
123
InternetService_0
Bool
123
InternetService_1
Bool
123
PaymentMethod_0
Bool
123
PaymentMethod_1
Bool
123
PaymentMethod_2
Bool
123
gender_0
Bool
123
Contract_0
Bool
123
Contract_1
Bool
123
Churn_0
Bool
1DSLMailed checkFemaleOne yearNo1001011100001011
2DSLMailed checkMaleMonth-to-monthNo1000101100000101
3Fiber opticElectronic checkMaleMonth-to-monthYes0110100010010100
4Fiber opticElectronic checkMaleMonth-to-monthYes0110100010010100
5Fiber opticMailed checkFemaleMonth-to-monthYes0101100010001100
6DSLCredit card (automatic)FemaleMonth-to-monthNo1001101100101101
7Fiber opticBank transfer (automatic)FemaleTwo yearNo0101001011001001
8Fiber opticCredit card (automatic)MaleTwo yearNo0100001010100001
9DSLElectronic checkFemaleMonth-to-monthNo1011101100011101
10DSLMailed checkFemaleTwo yearNo1001001100001001
11DSLCredit card (automatic)MaleTwo yearNo1000001100100001
12Fiber opticCredit card (automatic)FemaleTwo yearNo0101001010101001
13Fiber opticElectronic checkFemaleMonth-to-monthNo0111101010011101
14Fiber opticBank transfer (automatic)FemaleTwo yearNo0101001011001001
15DSLBank transfer (automatic)FemaleTwo yearNo1001001101001001
16Fiber opticCredit card (automatic)FemaleTwo yearNo0101001010101001
17DSLMailed checkFemaleOne yearNo1001011100001011
18Fiber opticElectronic checkFemaleMonth-to-monthNo0111101010011101
19DSLCredit card (automatic)MaleOne yearYes1000010100100010
20DSLElectronic checkMaleMonth-to-monthYes1010100100010100
21NoElectronic checkFemaleOne yearNo0011011000011011
22Fiber opticElectronic checkFemaleMonth-to-monthYes0111100010011100
23Fiber opticElectronic checkFemaleMonth-to-monthNo0111101010011101
24NoMailed checkFemaleMonth-to-monthNo0001101000001101
25NoMailed checkFemaleMonth-to-monthYes0001100000001100
26DSLBank transfer (automatic)FemaleMonth-to-monthYes1001100101001100
27Fiber opticBank transfer (automatic)FemaleOne yearNo0101011011001011
28NoCredit card (automatic)MaleTwo yearNo0000001000100001
29NoBank transfer (automatic)MaleOne yearNo0000011001000011
30NoBank transfer (automatic)FemaleTwo yearNo0001001001001001
31Fiber opticCredit card (automatic)MaleOne yearNo0100011010100011
32NoBank transfer (automatic)FemaleOne yearNo0001011001001011
33Fiber opticBank transfer (automatic)MaleOne yearNo0100011011000011
34NoElectronic checkFemaleOne yearNo0011011000011011
35DSLCredit card (automatic)MaleTwo yearNo1000001100100001
36NoElectronic checkFemaleTwo yearNo0011001000011001
37Fiber opticBank transfer (automatic)FemaleMonth-to-monthNo0101101011001101
38Fiber opticElectronic checkFemaleMonth-to-monthNo0111101010011101
39NoBank transfer (automatic)FemaleTwo yearNo0001001001001001
40Fiber opticBank transfer (automatic)MaleMonth-to-monthNo0100101011000101
41DSLElectronic checkMaleMonth-to-monthYes1010100100010100
42DSLMailed checkFemaleOne yearNo1001011100001011
43NoCredit card (automatic)MaleTwo yearNo0000001000100001
44DSLBank transfer (automatic)MaleOne yearNo1000011101000011
45DSLMailed checkMaleMonth-to-monthNo1000101100000101
46DSLBank transfer (automatic)MaleTwo yearNo1000001101000001
47DSLCredit card (automatic)FemaleOne yearNo1001011100101011
48Fiber opticElectronic checkFemaleOne yearNo0111011010011011
49DSLMailed checkMaleMonth-to-monthNo1000101100000101