get_dummies(data, prefix=None, prefix_sep='_', dummy_na: 'bool' = False, columns=None, sparse: 'bool' = False, drop_first: 'bool' = False, dtype: 'Dtype | None' = None) -> 'DataFrame'
Reference the user guide <reshaping.dummies>
for more examples.
Data of which to get dummy indicators.
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, :None:None:`prefix`
can be a dictionary mapping column names to prefixes.
If appending prefix, separator/delimiter to use. Or pass a list or dictionary as with :None:None:`prefix`
.
Add a column to indicate NaNs, if False NaNs are ignored.
Column names in the DataFrame to be encoded. If :None:None:`columns`
is None then all the columns with :None:None:`object`
or category
dtype will be converted.
Whether the dummy-encoded columns should be backed by a SparseArray
(True) or a regular NumPy array (False).
Whether to get k-1 dummies out of k categorical levels by removing the first level.
Data type for new columns. Only a single dtype is allowed.
Dummy-coded data.
Convert categorical variable into dummy/indicator variables.
Series.str.get_dummies
Convert Series to dummy codes.
>>> s = pd.Series(list('abca'))This example is valid syntax, but we were not able to check execution
>>> pd.get_dummies(s) a b c 0 1 0 0 1 0 1 0 2 0 0 1 3 1 0 0This example is valid syntax, but we were not able to check execution
>>> s1 = ['a', 'b', np.nan]This example is valid syntax, but we were not able to check execution
>>> pd.get_dummies(s1) a b 0 1 0 1 0 1 2 0 0This example is valid syntax, but we were not able to check execution
>>> pd.get_dummies(s1, dummy_na=True) a b NaN 0 1 0 0 1 0 1 0 2 0 0 1This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({'A': ['a', 'b', 'a'], 'B': ['b', 'a', 'c'],This example is valid syntax, but we were not able to check execution
... '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 1This example is valid syntax, but we were not able to check execution
>>> 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 0This example is valid syntax, but we were not able to check execution
>>> 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 0This example is valid syntax, but we were not able to check execution
>>> 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.0See :
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them