例如csv中的变量是:
a│b │
5│12│
我想要将csv中a的值解析为变量并打印值+ 5
答案 0 :(得分:1)
如果a
始终位于第一列,您可以按行索引0
引用它:
import csv
# assuming file is named 'csvfile.csv' in the current directory
with open('csvfile.csv', newline='') as csvfile:
# read the csv file and specify the delimiter
csvreader = csv.reader(csvfile, delimiter="|")
#skip the header row
next(csvreader)
# for every data row in the file, add 5 to the number in the
# first column and print the result
for row in csvreader:
value_of_a = row[0]
print(float(value_of_a) + 5)