如何在python中浏览数组的列

问题描述 投票:0回答:1

我有一个我用熊猫导入的csv文件

file3 = 'C:/Users/asus/Desktop/spmf/lignes.csv'
names = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q']
ligne = read_csv(file3, names=names, delimiter=';')
array3 = ligne.values

我想浏览这个表,并且对于每行我想要访问其列的值来检索它们并在另一个方法中使用它们,所以我们需要两个嵌套循环“for”,用于行和列,但我不知道如何在python中创建它们,然后为每个列如何在变量中检索它的值

这是我的文件的一个例子

5.0                         
1   7   11  13  14  16      
0   1   4   7   8   11  15  
0   1   3   4   5   7   11  13
0   1   3   4   5   7   11  13
0   1   3   4   5   7   11  13
python pandas
1个回答
0
投票

如果你只是想加载一个csv文件并逐行遍历它,那么一个快速的脏方法是:

file3=open('C:/Users/asus/Desktop/spmf/lignes.csv')
for row in file3:
    for col in row.split(",")[:-1]:
        #do something with the row value
        print(col)
file3.close()

虽然如果你不想读到第一行,你可以在for循环之前添加file3.readline()

© www.soinside.com 2019 - 2024. All rights reserved.