Forum Discussion

Jeanbar99's avatar
Jeanbar99
Copper Contributor
Sep 20, 2023

The pandas code read_excel() does not work in Python/Excel, unlike in native Python.

I have an issue when I try to read a specific workbook in Excel using pandas read_excel()

The following code was tested natively and it worked:

 

import pandas as pd
pth = "C:/Users/XXXX/Python 101/SUBPATH/"
input = "inputworkbook.xlsx"
wb = pth + input
df1 = pd.read_excel(wb, sheet_name="Sheet1", skiprows=1)

 

When I try to execute it from an excel workbook, I got this error message :

FileNotFoundError: [Errno 2] No such file or directory:

'C:/Users/XXXX/Python 101/SUBPATH/inputworkbook.xlsx'

 

Could you explain me why it doesn't work the same ? (Thanks)

  • Jeanbar99 

    That's data security, more details in related post.

    I don't think that's a big issue. You may Power Query external file (or any other source) and do nothing with it, just save as connection only. Next on Python

    df=xl("MyConnectionName")

    and do all transformations with Python.

    • Jeanbar99's avatar
      Jeanbar99
      Copper Contributor

      SergeiBaklan 

      Thanks for your reply. It is unfortunate. Do you know the reason why ?

      Python is easier (more flexible) than Power Query for ETL (from my point of view).

      • SergeiBaklan's avatar
        SergeiBaklan
        MVP

        Jeanbar99 

        That's data security, more details in related post.

        I don't think that's a big issue. You may Power Query external file (or any other source) and do nothing with it, just save as connection only. Next on Python

        df=xl("MyConnectionName")

        and do all transformations with Python.

    • Dimitri_'s avatar
      Dimitri_
      Copper Contributor

      Very helpful , thank you so much! The screenshot above is so useful.

       

      Shouldn't Excel say in the Initialization page  (with the list of libraries) that pd.read_excel/pd.read_csv is disabled?

      Excel goes through the trouble of pre-installing Pandas , and then disables the most important feature without saying anything? 

      CoPilot was not helpful either, it didn't say that read_excel is disabled.

Resources