从csv文件导入数据时,为什么会收到此python错误?

时间:2018-09-09 17:58:43

标签: python type-conversion

我正在尝试从csv文件导入数据并将数据转换为int。但我收到此错误:

year = int(i[0])
ValueError: invalid literal for int() with base 10: ''

由于将月份和日期转换为整数,我也收到此错误

with open('tide.csv', 'w') as tides_data:
tides = csv.writer(tides_data, delimiter=' ',
                   quotechar='|', quoting=csv.QUOTE_MINIMAL)
with open('test_csv.csv', 'r') as data_file:
    data = csv.reader(data_file, delimiter=',')
    for i in data:
        year = 2018 #the program has a bug here. please change so it can bring in the year from the csv file
        month = int(i[1])
        day = int(i[2])
        time = str(i[3])

here is the csv file

0 个答案:

没有答案