Reputation: 1
I am using Jupyter Notebooks under "https://jupyter.org/try" to read my csv file. I tried the following methods, and none of them works. I installed and imported pandas as pd.
top3 = pd.read_csv('C:\Users\mailcomputer\Downloads\Crime_Data_from_2020_to_Present')
top3 = pd.read_csv(r'C:\Users\mailcomputer\Downloads\Crime_Data_from_2020_to_Present')
top3 = pd.read_csv('C:/Users/mailcomputer/Downloads/Crime_Data_from_2020_to_Present')
top3 = pd.read_csv(r'C:/Users/mailcomputer/Downloads/Crime_Data_from_2020_to_Present')
top3 = pd.read_csv('C:\\Users\\mailcomputer\\Downloads\\Crime_Data_from_2020_to_Present')
top3 = pd.read_csv('C:\Users\mailcomputer\Downloads\Crime_Data_from_2020_to_Present.csv')
top3 = pd.read_csv(r'C:\Users\mailcomputer\Downloads\Crime_Data_from_2020_to_Present.csv')
top3 = pd.read_csv('C://Users//mailcomputer//Downloads//Crime_Data_from_2020_to_Present.csv')
top3 = pd.read_csv(r'C://Users//mailcomputer//Downloads//Crime_Data_from_2020_to_Present.csv')
Upvotes: 0
Views: 517
Reputation: 9780
You list a lot of commands you tried that look to be targeting your local user files saved in your system's file hierarchy, like C:\Users\mailcomputer\Downloads\...
. You won't be able to do it that way. Alas, though there is an easy way to achieve what you want.
First, some background on why it won't work that way you are trying by putting in the path on your local machine's file system...
On the 'Try Jupyter' page, probably right above where you selected your interface, there is a paragraph with symbols to emphasize the warnings:
⚠️Experimental ⚠️ several of the environments below use the JupyterLite project to provide a self-contained Jupyter environment that runs in your browser. This is experimental technology and may have some bugs, so please be patient and report any unexpected behavior in the JupyterLite repository."
Plus, you'll note that there and at the JupyterLite site itself it status is stated as "experimental", "cutting-edge", "unofficial", etc.
It is best to treat JupyterLite as running in a remote virtual machine. It is in fact running inside your local browser via webassembly (WASM), but because you cannot easily connect those two at this time because of security concerns with letting a website access your hard drive's contents, it is best to think of it as a 'remote' machine in practice.
So you cannot point JupyterLite at files on your local machine the way you are trying, but you can make the connection yourself easily enough in what you may consider a workaround...
The virtual machine running JupyterLite from inside your browser includes a virtual file system. You just need to 'upload' your file on your local machine's file storage system to the virtual file system running deep inside your browser where you cannot really get at things easily. You can 'upload' to JupyterLite just like you would upload to a remote machine's file server. Specifically, how to do it depends on the flavor of Jupyter you are using with JupyterLite. In other words, what tile you selected to start up the session from the 'Try Jupyter' page.
JupyterLab-flavor JupyterLite interface
For the JupyterLab-flavor JupyterLite interface you drag-and-drop in the file next to your running .ipynb
. You'll know if you are in the JupyterLab-like interface if you see a file navigation pane on the left side of your Jupyter session. You can click on a file in your system's file navigation interface and then hold down the button and drag it into the file browser pane on the left. When you have the file dragged into that pane, a gray dashed border will light up and you can release the mouse button to drop it in. Depending on the file size it will take a few seconds to 'upload' into the virtual file system. You should see progress along the bottom if it is indeed a large .CSV
file.
Notebook-flavor JupyterLite interface
For the Notebook-flavor JupyterLite interface, you click on the logo like a lightbulb in the upper left and then from the Jupyter Dashboard use the 'Upload
' button in the upper right side to get your local file into the virtual file system where your running .ipynb
file is stored.
Once you have done the steps appropriate to the interface flavor in which you are working, your file should appear among the files on JupyterLite's virtual file system. The hurdle has been cleared now.
Now you can use your .CSV
file with code in a cell in your JupyterLite session, like so:
top3 = pd.read_csv('Crime_Data_from_2020_to_Present')
There are still other limitations with the Pyodide-based kernel that JupyterLite uses, see my list at the bottom here or what I say here for more about that.
That covered how to get things into the JupyterLite file system; however, you'll want to also do the reverse for anything you care about.
It is always best to 'download' anything useful you make soon after you make it, and keep a copy in your machine's file storage system. You will actually use JupyterLite's 'Download
' abilities to do this step. This advice to download files pertains notebook files as well as any other artifacts you generate. Don't consider anything in JupyterLite's file system as permanently stored. As you'll find it not very accessible, the virtual file system in JupyterLite isn't very stable in the longterm. If you clear your browser cache, reinstall your browser, or move browsers or machines, you won't have access. So treat it as a 'remote' system in practice.
You can still fairly easily try Jupyter, both JupyterLab or the document-centric Notebook interface in conjunction with a typical, full Python kernel (ipykernel), instead of a Pyodide-based one, without installing anything, logging in, or signing-up for anything.
Go here and click the 'launch binder
' badge for JupyterLab. You can then switch to Jupyter Notebook, by choosing from the under the 'Help
' menu > 'Launch Classic Notebook
'.
See more about MyBinder here because there are considerations to make with use there, too, as these are temporary sessions. And there are ways to customize the environment as well. (You can even try cutting-edge versions of Jupyter without touching your own local system. A good list of the options can be found here.)
Installing Jupyter on your own machine may be good in the long run & JupyterLab Desktop is the easiest way to get started with that.
Upvotes: 0