DataFrame Indexing with a date series
Question: I'm new to Python and Pandas, and am having some trouble indexing by a date
series. I am trying to pull data into a DataFrame from a SQLite db that
consists of a date in format 'mm/dd/yyyy' and an equity price. I then create a
new DataFrame using set_index to index the prices by the dates. How can I set
the new index as a dateseries using the dates from my dataset? Does this
require a datetime conversion or does DataFrame have the ability to convert
from an object to a dateseries?

Below is the code I am using:

    
    
    import sqlite3 as db
    import pandas as p
    
    dbcon = db.connect(...ETF_DATA_TEST.db)
    c = dbcon.cursor()
    c.execute(""" QUERY """)
    rs =p.DataFrame.from_records(c.fetchall(),columns =['Date','Price'])
    data = rs.set_index('Date')
    

Thanks


Answer: You can use datetime.datetime.strptime to parse your 'Date' strings and then
construct numpy.datetime64 values from the datetime.datetime types:

    
    
    data = rs.reindex(numpy.array([(lambda x : datetime.datetime.strptime(x,'%m/%d/%Y'))(x) for x in rs['Date']],dtype='datetime64[us]')
    

