我有一个Excel文件,我需要从中获取一些数据。当我使用常规整数时,一切正常,但现在我陷入困境 - 如何更改行值?这就是我现在拥有的东西
dict_keys = ['Id', 'First name', 'Age', 'Condition Name', 'BiRad', 'Relevant Modality']
dict_values = [p_id, person_name, p_age, name, br, r]
if f == 'Mass':
#concatvals accepts (row, col, width, start, stop)
shape = concatvals(row, 14, 5, 14, 19) #if row = 0
margin = concatvals(row, 14, 5, 14, 19) #here row should be 1
density = concatvals(row, 14, 5, 14, 19) # and here 2 - how to achieve that?
dict_keys += ['Relevant Finding','Shape', 'Margin', 'Density']
dict_values += [f, shape, margin, density]
这就是我的尝试:
if f == 'Mass':
params = [shape, margin, density]
loc = (row, 14, 5, 14, 19)
for param in params:
params[i] = concatvals(loc)
loc[0] +=1
但没有成功走得更远。有什么建议?谢谢!
答案 0 :(得分:0)
使row
成为循环参数,并将计算出的值保存在数组中:
dict_keys = ['Id', 'First name', 'Age', 'Condition Name', 'BiRad', 'Relevant Modality']
dict_values = [p_id, person_name, p_age, name, br, r]
#concatvals accepts (row, col, width, start, stop)
vals = []
for row in range(3):
vals += concatvals(row, 14, 5, 14, 19)
dict_keys += ['Relevant Finding','Shape', 'Margin', 'Density']
dict_values += [f]
dict_values += vals
答案 1 :(得分:0)
你有点混淆你使用dict__
来表示不是dict的东西,而是一个列表...如果我理解你想要的东西我会到达这个:
params = {'Mass': ['shape', 'margin', 'density'],
'Next': ['some', 'other', 'list']}
if f == 'Mass':
loc = (row, 14, 5, 14, 19)
result = [f]
for param in params[f]:
result.append(concatvals(loc))
loc[0] +=1
dict_keys += ['Relevant Finding','Shape', 'Margin', 'Density']
dict_values += result
elif f == 'Next':
... etc ...