[英]How can I fix this: TypeError: unsupported operand type(s) for /: 'tuple' and 'float'?
I am trying to use the row values to get the C_vel
values. 我正在尝试使用行值来获取
C_vel
值。
The code: 编码:
wb = op.load_workbook('Canopy\Scripts\De Velliers.xlsx')
ws = wb ['Sheet1']
for row in ws.rows:
for cell in row:
print(cell.value)
print "----------"
C_vel = ws.rows / (A_c * rho)
print "C_vel: ", C_vel
The error message: 错误信息:
TypeError
Traceback (most recent call last)
C:\Users\Fraixxer Fraiz\Canopy\scripts\franis 1.py in <module>()
26 print(cell.value)
27 print "----------"
---> 28 C_vel = ws.rows / (A_c * rho)
29 print "C_vel: ", C_vel
30
TypeError: unsupported operand type(s) for /: 'tuple' and 'float'
You can not do mathematical operations on tuples. 您不能对元组进行数学运算。 Using numpy you could convert the tuple to an array first.
使用numpy,您可以先将元组转换为数组。 Mathematical operations can be performed on numpy arrays.
可以对numpy数组执行数学运算。
import numpy as np
wb = op. load _ workbook ('Canopy\Scripts\De Velliers.xlsx')
ws = wb ['Sheet1']
for row in ws . rows:
for cell in row:
print(cell. value)
print "----------"
C_vel = np.array(ws. rows)/ (A_c * rho)
print "C_vel:",C_vel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.