I want to bin as efficiently as possible numbers of a Pandas dataframe column into the degree in a logarithm scale.
By logarithm scale, I mean the way to display numbers over a power(unit, degree) range:
| Degree | Power(10, degree) | Power(2, degree) |
|---|---|---|
| -2 | 0.001 | 0.25 |
| -1 | 0.1 | 0.5 |
| 0 | 1 | 1 |
| 1 | 10 | 2 |
| 2 | 100 | 4 |
Giving the following toy dataset:
df = pandas.DataFrame(data={'number' : [0.478, 897.12, 12.56, 8.89, 1578.45, 0.089, 0.007]})
I would like to easily calculate the column log_10_class:
| number | log_10_class |
|---|---|
| 0.478 | 0 |
| 897.12 | 3 |
| 12.56 | 2 |
| 8.89 | 1 |
| 1578.45 | 4 |
| 0.089 | -1 |
| 0.007 | -2 |