How to read numbers in python from csv file?

前端 未结 2 1976
有刺的猬
有刺的猬 2021-01-02 06:01

I have a csv file and I have to compute the mean for some of the columns. That\'s how I did:

file=csv.reader(open(\'tab.csv\',\'r\'))
n=[]
for row in file:
          


        
2条回答
  •  佛祖请我去吃肉
    2021-01-02 06:54

    Just add quoting:

    with open('tab.csv', newline='') as file:
        reader = csv.reader(file, quoting=csv.QUOTE_NONNUMERIC)
        n=[]
        for row in reader:
            n.append(row[8])
    

提交回复
热议问题