1df['ageD'], bins = pd.qcut(df.iloc[:, 0], 2, retbins=True)
2left = (df["age"].values <= bins[:,None]).T.astype(int)
3dl = pd.DataFrame(left, columns=["(-inf, {}]".format(b) for b in bins])
4dr = pd.DataFrame(1-left, columns=["({}, +inf)".format(b) for b in bins])
5dout = pd.concat([pd.get_dummies(df), dl, dr], axis=1)
6
1>>> dout
2 age ageD_[5, 30] ageD_(30, 70] (-inf, 5] (-inf, 30] (-inf, 70] (5, +inf) (30, +inf) (70, +inf)
30 5 1 0 1 1 1 0 0 0
41 23 1 0 0 1 1 1 0 0
52 43 0 1 0 0 1 1 1 0
63 70 0 1 0 0 1 1 1 0
74 30 1 0 0 1 1 1 0 0
8