数据值是这样的
Survived | age |
---|---|
0 | 22.0 |
1 | 38.0 |
1 | 26.0 |
1 | 35.0 |
0 | 35.0 |
0 | null |
0 | 54.0 |
0 | 2.0 |
1 | 27.0 |
1 | 14.0 |
1 | 4.0 |
1 | 58.0 |
0 | 20.0 |
0 | 39.0 |
0 | 14.0 |
1 | 55.0 |
0 | 2.0 |
1 | null |
0 | 31.0 |
1 | null |
age_interval = [(lower, upper) for lower, upper in zip(range(0, 96, 5), range(5, 101, 5))]def age_partition(age): """ 将年龄分类 """ for lower, upper in age_interval: if age is None: return "None" elif lower <= age <= upper: return f"({lower}, {upper})"
我想对age一列进行修改,比如把22.0改为(20, 30),把38改成(30, 40)
上面的代码是对age值进行修改的函数
我应该如何对age列进行修改呢?
相关分类