'TypeError:不能在if子句中将序列乘以'float''类型的非int。在Python中 [英] 'TypeError: can't multiply sequence by non-int of type 'float'' within if clause. in Python
本文介绍了'TypeError:不能在if子句中将序列乘以'float''类型的非int。在Python中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里,从一个大的数据文件拆分成具有相同第4列的不同行,我试图绘制一条线,只有第3列每行的最高10%的条目:
Here, from a large data file split into different rows with the same 4th column, I'm trying to plot a line, with only the highest 10% of entries from each row from the 3rd column:
我的代码如下:
M1 = max(str(int(row1[i][2]))) #maximum value from row1, 3rd column
M2 = max(str(int(row2[j][2])))
if row1[i][2] >= M1*(0.1):
plt.plot....
这给了我错误:
if row1[i][2] >= M1*float(0.1):
TypeError: can't multiply sequence by non-int of type 'float'
我的行看起来像这样(每行在不同的行上):
my rows look like this (each row on separate line):
[[1, -1, 10, 0]]
[[2, 1, 20, 5]]
[[3, 2, 15, 10], [4, 2, 50, 10], [5, 2, 90, 10]]
[[6, 3, 15, 11]]
[[7, 4, 50, 11]]
[[8, 5, 90, 11]]
[[9, 6, 13, 14]]
[[10, 7, 50, 14]]
[[11, 8, 70, 14], [12, 8, 95, 14], [13, 8, 75, 14]].....
任何帮助都将不胜感激!提前致谢
Any help would be greatly appreciated!! Thanks in advance
推荐答案
从中删除 str(int())
MAX(STR(INT(ROW1 [I] [2])))
。你不能用字符串来乘以任何东西
你也不能将列表
转换为 int
。
Just remove str(int())
from max(str(int(row1[i][2])))
. You can't multipy anything by a string
neither can you convert a list
to int
.
这篇关于'TypeError:不能在if子句中将序列乘以'float''类型的非int。在Python中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文