当我尝试使用字段文本和日期读取 csv 文件时,出现错误
text_column_index = header.index('text')
ValueError:“文本”不在列表中
代码:
with open(source_file_path, 'r') as input_file:
csv_reader = csv.reader(input_file, delimiter='\t')
header = next(csv_reader)
text_column_index = header.index('text')
date_column_index = header.index('date')
word_frequency = {}
for line in csv_reader:
self.size += 1
words = self.tokenize(line[text_column_index])
date = line[date_column_index]
if date > self.end_date:
self.end_date = date
elif date < self.start_date:
self.start_date = date
我究竟做错了什么?