I'm reading in Excel files into pandas and then attempting to insert the values into postgres db. I've converted the data into python dates using the following code:
date_val = 42565.0
year, month, day, hour, minute, sec = xlrd.xldate_as_tuple(date_val, 0)
py_date = "%02d.%02d.%04d" % (day, month, year)
I haven't though been able to find a solution for passing empty values in the date columns to postgres using (psycopg2), python 2.7.12. Some of the values in the columns are empty and pd.read_excel
is parsing those values to NaN
. The error I am getting when trying to insert the data to postres db is:
<class 'sqlalchemy.exc.ProgrammingError'>, ProgrammingError('(psycopg2.ProgrammingError) column "created_at" is of type date but expression is of type double precision\nLINE 1: ...at, 0.0, \'NaN\'::float, 9410, 921, 111, \'NaN\'::flo...\n
I have tried to fill in those cells with empty string, zero as integer or string but I recieve an error everytime.
df['created_at'].fillna()
Any ideas how I should parse these values?
Thank you.