Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas bins dummy

df['ageD'], bins = pd.qcut(df.iloc[:, 0], 2, retbins=True)
left = (df["age"].values <= bins[:,None]).T.astype(int)
dl = pd.DataFrame(left, columns=["(-inf, {}]".format(b) for b in bins])
dr = pd.DataFrame(1-left, columns=["({}, +inf)".format(b) for b in bins])
dout = pd.concat([pd.get_dummies(df), dl, dr], axis=1)
Comment

pandas bins dummy

>>> dout
   age  ageD_[5, 30]  ageD_(30, 70]  (-inf, 5]  (-inf, 30]  (-inf, 70]  (5, +inf)  (30, +inf)  (70, +inf)
0    5             1              0          1           1           1          0           0           0
1   23             1              0          0           1           1          1           0           0
2   43             0              1          0           0           1          1           1           0
3   70             0              1          0           0           1          1           1           0
4   30             1              0          0           1           1          1           0           0
Comment

PREVIOUS NEXT
Code Example
Python :: python write into a file 
Python :: download python libraries offline 
Python :: multiple inputs in one line- python 
Python :: python dict if key does not exist 
Python :: django email 
Python :: python outlook 
Python :: opencv webcam 
Python :: discord.py events 
Python :: create new dataframe from existing data frame python 
Python :: binary to decimal python 
Python :: Append a line to a text file using the write() function 
Python :: lamda in pyton 
Python :: sort lexo python 
Python :: tuple in python 3 
Python :: python use variable inside pandas query 
Python :: combining strings 
Python :: can a function output be save as a variable python 
Python :: Python basic discord bot 
Python :: python file save 
Python :: DIVAB Solution 
Python :: python logging variables extra 
Python :: Math Module exp() Function in python 
Python :: use functions to resample pandas 
Python :: python set cookies 
Python :: anaconda python 3.6 download 
Python :: numpy 
Python :: CVE-2018-10933 
Python :: sns boxplot ylabelsize 
Python :: python flask rest api 
Python :: read mouse log python 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =