1 回答
TA贡献1852条经验 获得超1个赞
使用numpy方法解决了这个问题。此方法将值(或值)映射到条柱中,例如,年龄 27 将映射到第二个间隔(索引 1),代码为:digitizearray
import pandas as pd
import numpy as np
data = {'5000': ['18.67','19.79','22.16','26.38','29.17'],
'7500': ['20.07','21.28','23.82','28.36','31.99'],
'10000': ['21.46', '22.76', '25.48', '30.33', '34.81']}
index = np.array([25, 30, 35, 40, 45])
transition_table = pd.DataFrame(data, index=index)
def get_value(age, sum_assured):
row = np.digitize(age, transition_table.index, right=True)
col = str(sum_assured)
return transition_table.iloc[row, :][col]
用法:
age = int(input("Enter age"))
sum_assured = input("Enter Sum Assured")
get_value(age, sum_assured)
结果:
>>Enter age 27
>>Enter Sum Assured 10000
>>'22.76'
希望这有帮助,如果有什么不清楚的地方,请写一条评论。
添加回答
举报