Python And Mssql: Filtering Techniques While Retrieving Data From Sql
I have a MS SQL Table as follows Device ID Timestamp Avg_PF THDV_Sum 863071010842661 2014-01-01 22:05:57 4.0 7.0 865733020495321 2016-08-19 17:20:
Solution 1:
I would go about it like this:
from sqlalchemy import create_engine
%%time -- just to measure
# Parameters
ServerName = "SQLSRV01" -- your input
Database = "Database"
Driver = "driver=SQL Server Native Client 11.0"# Create the connection
engine = create_engine('mssql+pyodbc://' + ServerName + '/' + Database + "?" + Driver)
df = pd.read_sql_query ("SELECT Device ID, Timestamp, Avg_PF, THDV_Sum
FROM mytable
WHERE Timestamp >= '2018-10-01'"
, engine)
Solution 2:
Use the parse_dates argument of the read_sql_query function like so:
df_select = pd.read_sql_query(sql, conn, parse_dates=['Timestamp'])
Post a Comment for "Python And Mssql: Filtering Techniques While Retrieving Data From Sql"