Reputation: 69
I have stored multiple snowflake queries in an excel file and i'm trying to write a python program to execute those queries and export the result set into different CSV files in my local path. When I execute the program, it reads all the queries but exports only one query result into a CSV file.
from EXCEL_CONNECTION import * ---python program for snowflake connection
from SNOWFLAKE_CONNECTION import *--- python program for excel connection
import pandas
cur = ctx.cursor()
try:
for row in ws.iter_rows(min_row=2, min_col=2):
for cell in row:
cur.execute(cell.value)
#one_row = cur.fetchall()
df = cur.fetch_pandas_all()
df.to_csv(r"excel_output_path\table.csv")
finally:
cur.close()
cur.close()
I couldn't figure out the mistake I'm doing and would really need some help here to make this work
Upvotes: 1
Views: 1566
Reputation: 25968
you are writing all results to the same files, so they are overwriting each other
df.to_csv(r"excel_output_path\table.csv")
count = 0
for row in ws.iter_rows(min_row=2, min_col=2):
for cell in row:
cur.execute(cell.value)
#one_row = cur.fetchall()
df = cur.fetch_pandas_all()
df.to_csv(r"excel_output_path\table" + str(count) + r".csv")
count += 1
Upvotes: 3