【发布时间】:2021-01-07 10:06:15
【问题描述】:
Table_3 =
safety_class factor
0 low 0.90
1 medium 0.85
2 high 0.80
3 very_high 0.75
我的代码适用于单行:
def l_factor(safety_class, *args, **kwargs):
'''This function provides longitudnal usage factor
based on the table 3-10'''
table = tables['Table_3']
value_search = safety_class
match_table_value = table[table['safety_class'].str.match(value_search)] # returns list o
usage_factor = match_table_value['usasge_factor']
longitudnal_usage_factor = usage_factor
return l_factor
safety_class = 'medium'
此代码适用于单行,但是如何将其转换为数组的输入?
safety_class = array(['medium', 'medium', 'medium', 'high', 'high'], dtype=object)
如何匹配这些类似于str.contain --> 字典的数组对象列表?
非常感谢任何帮助!提前致谢
【问题讨论】:
-
table3是什么类型的?
-
您的代码相当混乱,因为很多名称都相当不一致。 match_table_value 没有“usasge_factor”列(除非您的意思是因子?),即使代码中的任何地方都没有使用 l_factor,您最后也会返回 l_factor(除非您的意思是 longitudnal_usage_factor?)
标签: python dictionary object search match