Binned Number as one hot encoded vector in Pandas DataFrame

40 views Asked by At

Lets assume I have a DF like below:

No Cost
1 10.5
2 34
3 755
4 1203
5 323

I want to set a N number of bins (like a histogram) i.e. 5 bins on the "Cost" column, and basically concatenate the One Hot Vectors along with my DataFrame DF like below:

No Cost 1 2 3 4 5
1 10.5 1 0 0 0 0
2 34 0 1 0 0 0
3 755 0 0 0 1 0
4 1203 0 0 0 0 1
5 323 0 0 1 0 0
0

There are 0 answers