Python Forum
Appending Excel column value as CSV file name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Appending Excel column value as CSV file name
#1
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.

      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
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 249 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 347 Feb-07-2024, 12:24 PM
Last Post: Viento
  Help copying a column from a csv to another file with some extras g0nz0uk 3 403 Feb-01-2024, 03:12 PM
Last Post: DeaD_EyE
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 752 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,046 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 2,839 Feb-20-2023, 07:19 PM
Last Post: avd88
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 772 Feb-16-2023, 08:11 PM
Last Post: cubangt
  Import XML file directly into Excel spreadsheet demdej 0 799 Jan-24-2023, 02:48 PM
Last Post: demdej
  How to read csv file update matplotlib column chart regularly SamLiu 2 1,015 Jan-21-2023, 11:33 PM
Last Post: SamLiu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020