Answers for "get_dummies"

6

getting dummies and input them to pandas dataframe

note:
dummies = pd.get_dummies(df[['column_1']], drop_first=True)
df = pd.concat([df.drop(['column_1'],axis=1), dummies],axis=1)


note:for more that one coloum keep ading in the list 
dummies = pd.get_dummies(df[['column_1', 'column_2','column_3']], drop_first=True)
df = pd.concat([df.drop(['column_1', 'column_1'],axis=1), dummies],axis=1)
Posted by: Guest on May-11-2020
3

getting dummies for a column in pandas dataframe

note:
dummies = pd.get_dummies(df[['column_1']], drop_first=True)

note:for more that one coloum keep ading in the list 
dummies = pd.get_dummies(df[['column_1', 'column_2','column_3']], drop_first=True)
Posted by: Guest on May-11-2020
6

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
Posted by: Guest on March-29-2020
0

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
Posted by: Guest on September-22-2021

Python Answers by Framework

Browse Popular Code Answers by Language