【发布时间】:2020-09-15 21:30:46
【问题描述】:
我有一个 CSV,我想将每行的第 6 个元素读入一个列表,并将每行的第 7 个元素读入另一个列表。以下是我的代码:
import csv
import math
#open csv file and create fie reader
with open('weightheightdata.csv', 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
#skip first 2 lines (header lines)
next(reader)
next(reader)
#create list of e values using the 9th column of each row
actualWeight = []
predictedWeight = []
for row in reader:
actualWeight.append(float(row[6]))
predictedWeight.append(float(row[7]))
我收到错误消息:TabError: inconsistent use of tabs and spaces in indentation
在线:predictedWeight.append(float(row[7]))。
【问题讨论】:
-
你得到了
TabError,因为你混合了制表符和空格字符来缩进。使用其中一种——使用空格是首选的方式。大多数 IDE 和文本编辑器都可以配置为自动将一种转换为另一种。
标签: python list csv filereader