Python Forum

Full Version: Pandas converting date to epoch
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

ok, this has stumped me for at least the last 6 hours and i am ready to pull what little hair i have left out!

I have a dataframe that i filled from a .xls
in it is a couple dates

i am trying to take those and add them to my sqlite database but i have hit error after error..

my brain has fried so i am not going to attempt to post the whole progression into how i got here but this is where i am at: (i believe its error number 12 or so)..
#this is where is separate the dataframe item. i am trying to reduce it back to epoch
fd = fd_db.iloc[dfb]['8']
fd = fd.strftime('%Y-%m-%d')

# then I am trying to add it into my sqlite statement:

            sql_in = """INSERT INTO returns(
            id = """ + row['3'] + """, 
            efin = """ + row['2'] + """, 
            fname = """ + row['5'] + """, 
            lname = """ + row['4'] + """, 
            tin = """ + str(self.key) + """, 
            fedlvl = """ + str(fl) + """, 
            feddate = """ + str(fd) + """, 
            statelvl = """ + str(row['6']) + """, 
            statedate = '', 
            starttime = """ + str(self.key) + """, 
            adminbypass = '', 
            comment = '', 
            end_date = ''
            ) ON CONFLICT(id) DO UPDATE SET
            tin=""" + str(self.key) + """, 
            fedlvl=""" + fl + """, 
            feddate=""" + str(fd) + """,  
            statedate=''
            ;"""
the error:
Error:
fd = fd.strftime('%Y-%m-%d') AttributeError: 'float' object has no attribute 'strftime'
i am at my wits end.. any suggestions?

ps: the dates, some have dates (19-11-16) but a few are empty.. which i think is whats causing problems..
whatever this is getting
Quote:fd_db.iloc[dfb]['8']
its returning a float, not a string as expected
You can try to use .to_sql method of df-instance.