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.
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
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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() |
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
Larz60+ write Feb-07-2022, 01:08 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBcode tags on future posts.