Sometimes you would get a data sheet as CSV file which needs to import in SQL, the problem is CSV files don’t really care what data type in the sheet, unlike SQL.

Let’s say you have a books CSV file, and one of the columns in it is publication year, in SQL you would store it as an Integer. And all good you just cast fields in this column as integer and store it, the problem is that you also reading the header of the spreadsheet and it a string which can’t be converted to an integer. In this case, you would just start to insert data into your table from the second row. Here is how to do it:

import csv

f = open("books.csv")
reader = csv.reader(f)

# to skip the header row, othervise it would through an error when try to cast string into integer for the years
next(reader)