Carlos Orozco
Carlos Orozco

Reputation: 21

How to specify a path for Microsoft Azure Jupyter Notebooks?

I am trying to upload a Python script I wrote for Jupyter Notebook to Microsoft Azure Notebooks, but it is not working correctly.

The Microsoft Azure project has a folder with XLSX files that I am trying to read, and the Python script. When I run the Python script on Jupyter Notebook it doesn't access the folder I previously uploaded to the project.

path =r'/Users/chorozco/Documents/Dr.Irwin/6 Column Data Acquisition Converted'
filenames = glob.glob(path + "/*.xlsx")

path = os.getcwd()
files = os.listdir(path)
files

I am expecting the list of the files inside "6 Column Data Acquisition Converted", but instead I get a list of the files inside my Microsoft Azure Project:

Expectation: Script run from Anaconda in my computer

Reality: Script run from Microsoft Azure Notebooks

Upvotes: 1

Views: 2221

Answers (1)

Peter Pan
Peter Pan

Reputation: 24138

Just according to your code path =r'/Users/chorozco/Documents/Dr.Irwin/6 Column Data Acquisition Converted', I think you are working on MacOS, not Linux. However, Microsoft Azure Notebooks is based on Linux for running. So the difference of code os.listdir(path) between Azure Notebook and your local Anaconda is caused by the different implementation of Python for this feature os.listdir on different OS like MacOS other than Linux and Windows, the result without the files recursively listed in the directories.

Here is my steps as reference.

  1. I created a new project named Test for listing xlsx files in a path of Azure Notebook Project in my account of Microsoft Azure Notebooks, and to create a new folder 6 Column Data Acquisition Converted as the figures below.

    Fig 1.

    enter image description here

    Fig 2.

    enter image description here

  2. I created some xlsx files on my local Windows for uploading, then move to the folder I created in Azure Notebook project previously to do the upload operation as the figures below.

    Fig 3.

    enter image description here

    Fig 4.

    enter image description here

    Fig 5.

    enter image description here

    Fig 6.

    enter image description here

  3. I created a notebook in Python 3.6 to run the same code with yours.

    Fig 7.

    enter image description here

    Fig 8.

    enter image description here

  4. I found the result is as same as the code on my local Linux and Windows, but other than your result on MacOS.

    Fig 9. The almost same code run in Python 3.6 of Azure Notebook

    enter image description here

    Fig 10. The almost same code run in Python 2.7 of Azure Notebook

    enter image description here

    Fig 11. The result of os.listdir on Windows

    enter image description here

    Fig 12. The result of os.listdir on Linux

    enter image description here

So I think the issue was caused by MacPython, please check it again. Hope it helps.

Upvotes: 1

Related Questions