【发布时间】:2020-07-10 19:18:39
【问题描述】:
我正在尝试构建一个简单的系统,系统要求用户输入年龄,输入保额(或他/她想收到的金额),然后根据这些输入,系统将告诉用户他要支付的保费(或金额)。
到目前为止,我已经能够让代码工作(在某种程度上),但是我的问题现在是遍历所有列。
这是代码:
import pandas as pd
#data = pd.read_csv("/Users/Noel/Desktop/Transition.csv")
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']}
transition_table = pd.DataFrame(data, index=['18-25','26-30','31-35','36-40','41-45'])
print('Hello, welcome to Axe!')
age = int(input('Please enter the age of the Policyholder: '))
sum_assured = int(input('Please enter the Sum assured of the Policyholder: '))
if age >= 18 and age <= 25 and sum_assured == 5000:
row0 = transition_table.iloc[0, 0]
print(row0)
elif age >= 26 and age <=30 and sum_assured == 5000:
col0 = transition_table.iloc[1, 0]
print(col0)
print('A Policyholder of age ' + age + ' with a sum assured of ' + sum_assured + ' will pay a premium of ' )
所以当我输入年龄为 18 岁,保额为 5000 时,我应该会收到以下输出: 保额为 5000 的 18 岁保单持有人将支付 18.7 的保费
如果我输入年龄为 27 岁,保额为 10000,我希望收到以下输出: 保额为10000的27岁保单持有人将支付22.76的保费
我想我应该使用 for 循环来进行迭代,但我遇到了困难。
【问题讨论】:
标签: python pandas loops dictionary