ValueError:int()的无效文字,在Visual Studio代码中以10为底:

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

不理解为什么它不会读取此csv文件的正确性

import os
import csv


CURRENT_DIR = os.path.dirname(__file__)
file_path = os.path.join(CURRENT_DIR, 'sitka_weather_2018_full.csv')

with open(file_path) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    highs = []
    for row in reader:
        high = int(row[8])
        highs.append(high)


    print(highs)

我一直收到此错误:

ValueError                                Traceback (most recent call last)
~/ CrashCourse Python Notes/Chapter 16 CC/Downloading Date/csv format/highs_lows.py in 
     18     highs = []
     19     for row in reader:
---> 20         high = int(row[8])
     21         highs.append(high)
     22 

ValueError: invalid literal for int() with base 10:

任何帮助都会很棒

python database csv matplotlib int
1个回答
0
投票

CSV列8中的某处为空,您需要确定这是应终止程序的错误还是可以从中恢复的错误。以下代码记录了错误并继续进行处理。至少,这是调试问题的好方法。

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