Question: I have a dataframe, how can I convert the values in a column to a list of corresponding integers based on which range they belong to. For example,

```
test = pd.DataFrame({"price": [0.1, 0.5, 0.2, 0.11, 0.8, 0.3, 0.9, 1.0, 0.47]})
out[1]:
        price
    0   0.10
    1   0.50
    2   0.20
    3   0.11
    4   0.80
    5   0.30
    6   0.90
    7   1.00
    8   0.47

```

Then, I need to convert the values to integers based on their range, e.g., when x <= 0.1, make x = 1, and when 0.1 < x <= 0.2, make x = 2. The result looks like:

```
out[2]:
        price   price_new 
    0   0.10     1          # 0.10 belongs to [0, 0.1] ---> 1
    1   0.50     5          # 0.50 belongs to (0.40, 0.5] ---> 5
    2   0.20     2                .
    3   0.11     2                .
    4   0.80     8                .
    5   0.30     3
    6   0.90     9
    7   1.00     10
    8   0.47     5

```

I tried some methods, but they din't work very well. Please help! Thank you very much!

Answer: 
You can use pandas cut

```
bins = np.arange(0, 1.1, 0.1)
labels = np.arange(1, 11)
test['price_new'] = pd.cut(test.price, bins = bins, labels = labels)

price   price_new
0   0.10    1
1   0.50    5
2   0.20    2
3   0.11    2
4   0.80    8
5   0.30    3
6   0.90    9
7   1.00    10
8   0.47    5

```

Edit: Create bins with - and + inf to include extreme values.

```
bins = [-np.inf , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, np.inf ]

```
For this use case, you can just use the round function and scale the numbers to get your desired output.

```
import pandas as pd
df = pd.DataFrame({"price": [0.1, 0.5, 0.2, 0.11, 0.8, 0.3, 0.9, 1.0, 0.47]})
df['price_new'] = df.price.multiply(10).round()
print(df)
#Output:
   price  price_new
0   0.10        1.0
1   0.50        5.0
2   0.20        2.0
3   0.11        1.0
4   0.80        8.0
5   0.30        3.0
6   0.90        9.0
7   1.00       10.0
8   0.47        5.0

```