I am reading a data_frame
directly from a database using pandas.io.sql.read_frame
:
cnx = pandas.io.sql.connect(host='srv',user='me',password='pw',database='db')
df = pandas.io.sql.read_frame('sql_query',cnx)
It works nicely in retrieving the data. But I would like to parse one of the columns as a datetime64
, akin to what can be done when reading from a CSV file, e.g.:
df2 = pandas.io.read_csv(csv_file, parse_dates=[0])
But there is no parse_dates
flag for read_frame
. What alternative approach is recommended?
The same question applies to the index_col
in read_csv, which indicates which col. should be the index. Is there a recommended way to do this with read_frame?
This question is very old by now. pandas 0.10 is very old as well. In the newest version of pandas 0.16, the read_frame method has been depricated in favour of the read_sql. Even so, the documentation says that just like the read_csv function, it takes a parse_dates argument Pandas 0.16 read_frame
It seems the parse_dates argument appeared in 0.14, at the same time as read_frame was depricated. The read_sql function seems to be a rename of the read_frame, so just updating your pandas version to 0.14 or higher and renaming your function will give you access to this argument. Here is the doc for the read_sql function: Pandas 0.16 read_sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With