我得到了一个包含变量及其对应系数的excel文件,但没有模型文件。我已将该电子表格转换为字典(最终示例为标题为factors
的字典(下面的示例)。这是一个嵌套的字典。例如,CC按车辆类别分类,因此在CC键中,值是字典对于每个类,类本身都是基于value_class`列中的值。cc因子基于cc_class列中的cc类。
我将如何让python将列名与键匹配,将值与正确的类匹配,然后最终将正确的系数放入计算中?在df_result中找到计算和匹配项。
import pandas as pd
vn_value = {23000: 1, 30000: 2, 26000: 3}
g_cn_value = {2000:1, 3000: 2, 4000: 3}
la_value = {19000: .5, 20000: 1, 20500: 1.2}
unit_value_factors = {'VN':vn_value, 'G_CN':g_cn_value, 'LA':la_value}
package = {'VPN':.3, 'SPS':.5, 'LSS':.7, 'SCE':.8}
d_cc = {1700: 1.3, 1800:2.1}
E_cc = {1300:1.8, 1400:.6}
HD_cc = {1400:1.5, 1800:1.7, 1900:1.8}
cc_factors = {'D':d_cc, 'E':E_cc, 'HD':HD_cc}
factors = {'value':unit_value_factors, 'package_modifier':package, 'cc':cc_factors}
df_value_class = ['VN', 'VN', 'G_CN', 'LA']
df_value = [26000, 30000, 3000, 19000]
df_package = ['VPN', 'SPS', 'LSS', 'SCE']
df_cc_class = ['D', 'E', 'HD', 'HD']
df_cc = [1700, 1300, 1400, 1900]
value_factor = [3,2,2,.5]
package_factor = [.3, .5 ,.7, .8]
cc_factor = [1.3, 1.8, 1.5, 1.8]
df = pd.DataFrame({'value_class':df_value_class, 'value':df_value, 'package_modifier':df_package
, 'cc_class':df_cc_class, 'cc':df_cc, 'AI':df_sc_AI, 'MS':df_sc_MS})
df_result = pd.DataFrame({'value_class':df_value_class, 'value':df_value, 'value_answer':value_factor
, 'package_modifier':df_package, 'package_answer':package_factor, 'cc_class':df_cc_class
, 'cc':df_cc, 'cc_answer':cc_factor})
df_result['score'] = df_result['value_answer']*df_result['package_answer'] * df_result['cc_answer']