Python 尝试将行转换为浮点数以追加到列表中时发生TypeError

Python 尝试将行转换为浮点数以追加到列表中时发生TypeError,python,Python,我试图将数据集中的每一行附加到一个单独的列表中。但我得到了一个TypeError:当试图将每一行转换为浮点时,float参数必须是字符串或数字,而不是“list”,这样我就可以这样做 x_data = [random.sample(range(80), 20)]*1000 y_data = [random.sample(range(80), 20)]*1000 data = [x_data,y_data] n = 0 for row in data : if n == 0 :

我试图将数据集中的每一行附加到一个单独的列表中。但我得到了一个TypeError:当试图将每一行转换为浮点时,float参数必须是字符串或数字,而不是“list”,这样我就可以这样做

x_data = [random.sample(range(80), 20)]*1000
y_data = [random.sample(range(80), 20)]*1000

data = [x_data,y_data]

n = 0
for row in data :
    if n == 0 :
        n+=1
        continue
    x_data = []
    y_data = []
    for (x,y) in [(0,1),(2,3), (4,5), (6,7), (8,9), (10,11), (12,13), (14,15), (16,17), (18,19), (20,21), (22,23), (24,25), (26,27), (28,29), (30,31), (32,33), (34,35), (36,37), (38,39)] : 
        xcoord = float(row[x]) #Error occurs in this line
        ycoord = float(row[y])
        if xcoord >= 5 :
            x_data.append(xcoord)
            y_data.append(ycoord)
我试图将floatrow[x]更改为listmapfloatrow[x],但得到了相同的结果?

x\u数据和y\u数据是列表列表。random.sample将为您返回一个列表,您当前正在将该列表放入另一个列表中,*1000将只重复该内部列表1000次。我认为您只需进行以下更改:

x_data = random.sample(range(80), 20)*1000
y_data = random.sample(range(80), 20)*1000