I have a python function that queries a database, how can I write this to csv when I do not convert to dataframe? Or must I import dataframe and use that function?
Return works fine to see results in my consol, but now I would like to export as csv.
any help would be appreciated.
code:
import pandas as pd
import pyodbc, os
import datetime
from datetime import datetime
from pandas import ExcelWriter
import numpy as np
def date(businessDate):
con = pyodbc.connect(r'DSN='+'Stack',autocommit=True)
print('working')
sql = f"""
SELECT * FROM date
where businessDate = {businessDate}
"""
df_date = pd.read_sql(sql,con)
con.close()
return(df_date)