When using read_sql
in pandas the function requires to identify what columns should be treated as dates (see snippet below). But I don't know beforehand what columns are dates.
Given a select statement, I need to retrieve its column types and load the result set into a pandas dataframe. I was expecting pandas to identify the columns of type date and assign the type when the dataframe is created from the select.
What is the best way to identify the date types in the select statement or the dataframe? I'm trying to avoid running the statement with pyodbc
to detect the types.
import pyodbc
import pandas as pd
conn = pyodbc.connect....
sql_df = pd.read_sql(
"SELECT * FROM my_table",
conn,
parse_dates=[
'created_at',
'updated_at'
]
)