I would like to know the python code that converts Excel data into a csv file for each sheet.

NishimuraChinatsu-9854 756 Reputation points
2022-07-29T09:53:29.513+00:00

I would like to know the pyhon code that converts Excel data with 3 sheets into a csv file with synapse notebook acyivity.

The image looks like the one below.

Must be pyhon because it is a macro-enabled Excel file.

![![226076-image.png]1]1

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,378 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vinodh247 34,666 Reputation points MVP Volunteer Moderator
    2022-07-30T11:14:32.08+00:00

    Hi NishimuraChinatsu,

    Thanks for reaching out to Microsoft Q&A.

    Use the below python code to convert your excel(xls, xlsm...etc) into CSV files. You can run the query in your synapse notebook, just change the path according to your requirement. I have tried this out in my synapse environment it works good.

    import pandas as pd  
    excel_file = 'abfss://xxxxxx*anonymous user*.dfs.core.windows.net/Financial Sample_orig-3Sheets.xlsx'  
    all_sheets = pd.read_excel(excel_file, sheet_name=None)  
    sheets = all_sheets.keys()  
      
    for sheet_name in sheets:  
        sheet = pd.read_excel(excel_file, sheet_name=sheet_name)  
        sheet.to_csv("abfss://xxxxxxxx*anonymous user*xx.dfs.core.windows.net/%s.csv" % sheet_name, index=False)  
    

    226307-image.png

    226308-image.png

    Please Upvote and Accept as answer if the reply was helpful.

    1 person found this answer helpful.

  2. Vinodh247 34,666 Reputation points MVP Volunteer Moderator
    2022-08-01T05:59:03.04+00:00

    Yes it is a permission issue. To resolve this, check the below link where similar issue has been assisted.

    https://learn.microsoft.com/en-us/answers/questions/779065/error-this-request-is-not-authorized-to-perform-th.html

    Please Upvote and Accept as answer if the reply was helpful.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.