У меня проблемы с нежелательными значениями NULL в последних строках файла CSV. Например, файл CSV с двумя столбцами, который содержит 10 строк правильных данных и 5 дополнительных строк, которые, как я полагаю, являются пустыми ячейками. См. Вставку txt: -
a8,06/05/2020
a9,06/05/2020
a10,06/05/2020
,
,
,
,
,
Я использую CX_ ORACLE для импорта данных в базу данных, но он также импортирует 5 пустых строк с NULL.
Любое представление о том, как Я могу исключить пустые строки CSV в конце файла. Ниже приведен отрывок из моего импорта: -
# Initialize list that will serve as a container for bind values
L = []
UpdateLog ('Load CSV file into List...')
reader = csv.reader(open(map_drive + ':\\'+ sp_file), delimiter=',')
# the code exludes the column headers on row
UpdateLog ('Skip Header Row...')
next(reader)
for row in reader:
L.append(tuple(row))
# prepare insert statement
UpdateLog ('Creating INSERT Statement')
cursor.prepare(insert)
# execute insert with executemany
cursor.executemany(None, L)
# report number of inserted rows
UpdateLog ('Inserted: ' + str(cursor.rowcount) + ' rows into ' + table)
tmpRowCount = cursor.rowcount
cursor = connection.cursor()
#commit
connection.commit()
UpdateLog ('End import to '+ table)