Apr-17-2024, 10:17 AM
(Mar-19-2024, 08:31 PM)deanhystad Wrote: csv.reader returns a list of strings. You need to do any type conversion yourself. I don't think the csv library is a good choice for what you are doing. I don't think openpyxl is a good choice either. I would use pandas. It can read a csv file and do the type conversion, probably automatically, and it can write the results to a spreadsheet.
As a poor alternative you could fix the types here:
for row in reader: row[5] = int(row[5]) # Changing column 5 to an int. ws.append(row) wb.save(xlsx_file) # Should not be in loopYou could convert values in row from str to int/float/date/whatever before appending to the worksheet.
The file you treat as a CSV file is not a CSV file. It stops being a CSV file when you do this:
write_file.write(f'\nErrors: {error_count}\n')CSV files must be tabular. All rows in a CSV file must have the same number of values.
I forgot to reply to this, sorry, but I took your advice and I'm using pandas now, which is much better. Thank you!