Feb-06-2022, 10:32 PM
Hi All,
I am trying to execute a bunch of queries from an excel and loading the result of each queries in individual CSV files. Below is the python code I'm using.
I am trying to execute a bunch of queries from an excel and loading the result of each queries in individual CSV files. Below is the python code I'm using.
from EXCEL_CONNECTION import * from SNOWFLAKE_CONNECTION import * import pandas cur = ctx.cursor() wb = openpyxl.load_workbook(r"Input file path\QUERY.xlsx") ws = wb.get_sheet_by_name('Sheet1') try: for col in ws.iter_cols(min_row=2, min_col=1): for cols in col: name = (cols.value) for row in ws.iter_rows(min_row=2, min_col=2): for cell in row: cur.execute(cell.value) df = cur.fetch_pandas_all() df.to_csv(r"File_Path" + str(name) + r".csv") finally: print("success") cur.close()After running this Script i'm getting the below error and I could see the result of last query from the excel created as CSV and saved in the file path. could somebody please help me out here
Error:`handle = open(
OSError: [Errno 22] Invalid argument: "File_Path\nSelect * from xxx.xxx.xxx.csv"`
QUERY.xlsx format :
Table_name Query
Count 'Select * from sales'
Attribute 'Select * from party_sales'
Output expected :
Count.csv
Attribute.csv