pandas provides a method to execute sql queries against RDB. Use this to execute a stored procedure and create a pandas dataframe from the execution result. It can be expanded to data aggregation using pandas and subsequent graph drawing using matplotlib.
make_pandas_df.py
import sqlalchemy
import pandas as pd
q = 1
ym = 201604
CONNECT_INFO = 'mssql+pyodbc://hogehoge'
engine = sqlalchemy.create_engine(CONNECT_INFO, encoding='utf-8')
#Data frame creation
query = 'EXEC dbo.sp_rtrv4pandas @q = {0},@ym = {1}'.format(qq,ym)
df = pd.read_sql_query(query, engine,index_col =['prd'])
print(df)
Recommended Posts