Python Forum
Pandas converting date to epoch
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas converting date to epoch
#1
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..
Reply
#2
whatever this is getting
Quote:fd_db.iloc[dfb]['8']
its returning a float, not a string as expected
Reply
#3
You can try to use .to_sql method of df-instance.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Does a pandas have a date without a time? AlekseyPython 6 1,085 Feb-10-2021, 09:24 AM
Last Post: Naheed
  (Solved) Converting Dollar Amount Str to Int with Pandas calvinsomething 3 1,041 Nov-19-2020, 01:31 PM
Last Post: calvinsomething
  replace nan values by mean group by date.year, date.month wissam1974 5 4,050 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Obtaining Correct Date In Pandas DataFrame eddywinch82 14 2,809 Feb-17-2020, 11:45 AM
Last Post: eddywinch82
  Trying to Pass date to pandas search from input prompt curranjohn46 1 848 Oct-10-2019, 10:01 AM
Last Post: curranjohn46
  Need help passing date to pandas query curranjohn46 1 2,247 Oct-10-2019, 09:59 AM
Last Post: curranjohn46
  Pandas and Date: problem with operator.How to resolve frame 6 2,219 May-13-2019, 05:50 PM
Last Post: frame
  Working with date indexes (pandas) dervast 0 1,035 Apr-05-2019, 01:29 PM
Last Post: dervast
  Converting string the pandas dataframe chrismc 0 1,224 Jan-24-2019, 11:07 AM
Last Post: chrismc
  Error: Slicing a single date from Pandas cheerful 0 1,350 Jul-22-2018, 08:09 PM
Last Post: cheerful

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020