Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to get dummies in a dataframe pandas

df = pd.get_dummies(df, columns=['type'])
Comment

get_dummies

#this do dummie verable do a very intersting thing they turn calegorical 
#variables in numerical like M and F they can 0 for M and 1 for F  


pd.get_dummies(df.Gender)

	F	M
0	0	1
1	1	0
2	1	0
3	0	1
4	1	0
...	...	...
202	1	0
203	0	1
204	0	1
205	0	1
206	1	0
207 rows × 2 columns

Comment

get dummies pandas

df = pd.get_dummies(df, columns=['col1', 'col2', 'col3'])
Comment

pd.get_dummies

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

get dummies pandas

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

get dummies pandas

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

PREVIOUS NEXT
Code Example
Python :: flask blueprint 
Python :: stop procedure python 
Python :: python convert json string to class 
Python :: how to get value from set in python 
Python :: mechanize python 
Python :: random.sample python 
Python :: python .nlargest 
Python :: Setting Up Stylesheet Django 
Python :: list -1 python 
Python :: markers seaborn 
Python :: python randrange 
Python :: file methods in python 
Python :: fibonacci series using dynamic programmig approach 
Python :: python asyncio gather 
Python :: views.py django 
Python :: python for loop in array 
Python :: python train test val split 
Python :: python selenium send keys enter send 
Python :: generate random int python 
Python :: print string and variable python 
Python :: django queryset count 
Python :: set environment variable flask app 
Python :: python turtle set screen size 
Python :: django serve media folder 
Python :: numpy random choice 
Python :: envScriptsactivate.ps1 : File 
Python :: edit error page flask 
Python :: blender show python version 
Python :: standardscaler 
Python :: get output from transaction in brownie 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =