python很新,我正在努力解决一些问题。我从一个 CSV 文件中分解出一堆数据点,其中一个是日期(mm/dd/yyyy)。我正在使用该日期并将其拆分为每个“/”,以便将各个部分分成单独的列表。那就是我遇到麻烦的地方。在我的代码末尾,当我尝试打印超出零的列表的每个索引时,我得到了这些错误。最终,我想要对这三个单独的日期对象做的事情是将它们作为子列表添加到我现有的 ptInfo 列表(ptInfo[8]、ptInfo[9]、ptInfo[10])的末尾我该怎么做?
运行时错误 (IndexOutOfRangeException):索引超出范围:1 回溯:第 51 行,在脚本中
运行时错误 (IndexOutOfRangeException):索引超出范围:2 回溯:第 52 行,在脚本中
#import Points from CSV
import rhinoscriptsyntax as rs
import sys
import datetime
input_file = 'C:\Users\kenma\Dropbox (Personal)\Solo Work\Projects\Sweet Crude\Work\data\prepared_uic_data.csv'
#Init Lists
a = []
apis = [] #0
operators = [] #1
operatorNums = [] #2
wellTypes = [] #3
dates = [] #4
lats= [] #5
longs = [] #6
zoneAreas = [] #7
dateFrag = []
dateM = [] #8
dateD = [] #9
dateY = [] #10
file = open(input_file, 'r') #open file for reading
lines = file.readlines() #read lines into variable
file.close() #close the file
del lines[0] #delete first header line
for line in lines:
#remove the /n
line = line.strip()
# split line by the column
ptInfo = line.split(',')
a = ptInfo
# split line data into individual arrays
apis.append(ptInfo[0])
operators.append(ptInfo[1])
operatorNums.append(ptInfo[2])
wellTypes.append(ptInfo[3])
dates.append(ptInfo[4])
lats.append(ptInfo[5])
longs.append(ptInfo[6])
zoneAreas.append(ptInfo[7])
dateFrag = ptInfo[4].split("/")
print(dateFrag[0])
print(dateFrag[1])
print(dateFrag[2])