How to replace the values of a column with the mean of the values of the bin?

Viewed 88

Given the below DataFrame column:

0    -0.0985
 1    -0.0880
 2    -0.1068
 3    -0.2338
 4    -0.2807
 5    -0.1570
 6    -0.2043
 7    -0.0776
 8    -0.1572
 9    -0.0501
 10   -0.0926
 11   -0.2075
 Name: 2, dtype: float64)

and the pandas.qcut categorical and bins:

(0     bin_2
 1     bin_3
 2     bin_2
 3     bin_0
 4     bin_0
 5     bin_1
 6     bin_1
 7     bin_3
 8     bin_1
 9     bin_3
 10    bin_2
 11    bin_0
 Name: 2, dtype: category
 Categories (4, object): ['bin_0' < 'bin_1' < 'bin_2' < 'bin_3']

How to create a column with the same size, and replace each value by the mean of the values in the bin?

0 Answers
Related