while i asked some members they said to download it to local machine and all
but i am unaware of the steps to do it pls expalin it clearly
i guess you have to download the file first then.
import urllib.request
with urllib.request.urlopen("https://yoururl/file.csv") as u:
csv_data = u.read()
Screenshots, especially alone, aren’t sufficient to provide details of what you want to do and to help us sort out why it isn’t working.
Major point here is that you don’t show what file you are trying to read into Pandas because the screenshot cuts off the end of the filepath. Also it doesn’t show the full traceback so the information that would give isn’t fully there. Always include a description in text and any code you are trying to use as code text in the post.
That all said…
Are you trying to read into Pandas auto.csv
? I see that file there in the session now. So the cell that is #19 in the screenshot should have to code:
import pandas as pd
df = pd.read_csv("auto.csv")
Please if that isn’t what you are trying to do, describe the situation better?
If you are trying to get a file that is online somewhere?
I gather this file is online. But I have no idea where because I cannot see the URL and so I cannot test and maybe tell you why your approach isn’t working. Please provide the full link in text.
I will add the foolproof way is to download the file to you local machine as you would a normal file you wanted to work with on your machine, as if the source data or the server hosting it is only available temporarily. Then with that file on your local machine’s file system hierarchy you can then drag and drop it in to the same directory in JupyterLite where you notebook is. In this example, you’d drag and drop from your local machine into the file navigator pane on the left side in your screen shot.
You should think of the Pyodide kernel as a remote machine even though technically it all happens in your local machine. Pyodide running in your browser doesn’t have access to your local file system.
That route of downloading to your local machine and then putting it into the JupyterLite session is the foolproof way that will work all the time; however, obviously though that is not the most convenient, especially if you repeating it a lot. And so if you supply the URL I can test if you should be able to provide pd.read_csv()
that particular URL and expect it to work or not. (Honestly I’ve switched between using pyscript, JupyterLite, py.cafe, and a typical ipykernel so much lately, I cannot keep straight what limitations or approaches are needed in theory for providing a URL for the three pyodide-based options [the first three in my list] right now. Sometimes the theory doesn’t apply to certain .csv
s for other reasons because of the two servers or networks involved.)
Another thing to consider here is why you are working in JupyterLite? (I can tell because the ‘Python (Pyodide)’ kernel in the upper right side in the kernel indicator.) Is that necessary for your work? For novices, the limitations of JupyterLite sometimes make it not the best choice because they read things possible in JupyterLab and don’t realize that won’t quite work as simply in JupyterLite at this time. See the last paragraph here or the top of my reply here if you want to consider that option now.
Really sorry for late reply and very thanks for your concern not having a habit of checkinng emailos but i want this solution
this is a skill network lab in coursera of data science certificate
its a task of reading and saving CSV file from web
I dont the kernel(pyodide) this is what coursera provides .
here i am getting an OS error and asked in community forums they gave a solution which i cant understand i will provide that screen shot down. So pls explain it clearly like small things and processes too.
this is the link of the lab
“https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DA0101EN-SkillsNetwork/labs/Data%20files/auto.csv”
this is the file URL.|
!!!Pls deadlline is getting close!!!
Okay, so you have to stick with JupyterLite because this is via Coursera.
I already told you the foolproof way. Go that route if you are in a hurry.
The course will offer you support about what they use and will be more insightful.
You probably should include that and maybe someone here will have more insight.
ok i have a doubt
in foolproof way
Are you saying to paste my csv file path in read_csv() ?
and i tried it is showing error
or else i have to type my file name there . It is showing erroro too
and i cant understand the foolproof way
Can you please expalin it step wisely as iam from a non english country it is
difficult to understand means you can say it atomically
!!Thanks for your patience and i make sure this my last question !!
!!again sorry for troubling you !!!
Please read Getting good answers to your questions. I’d also suggest especially reading in the link to How do I ask a good question? at the bottom there. Your post from the get-go lacked information you had and could have shared. (And could have shared as text, preferably. Or screenshot along the text at the very least. Make things easy for those trying to help you.)
Two points in that post address exactly what you see:
“3. If
filepath
variable stores a URL address it will not work directly with **pandas.read_csv()` method here - this environment does not supper such usage (see #2). pandas.read_csv() can only e used to read stored CSV fiile (i.e. downloaded via a different method, see #2 again)”
“However, in this version of the lab, which operates on JupyterLite, the dataset needs to be downloaded to the interface using the provided code below.”
JupyterLite running on the coursera site cannot use a URL supplied to pandas.read_csv()
. It is stated clearly in both those quoted statements. And you even found that to be the case when you tried it.
Good for you for trying it and confirming. However, what did you try differently after being told that wouldn’t work, and experiencing it for yourself?
We keep going in circles because how to do it is spelled out in that post and I provided a more straightforward way that doesn’t involve writing code. Importantly, I, and the other person trying to help you in the screenshot, both think you may have done the download step the code way and then didn’t use it? This is why the person in the post in the screenshot is exasperated a bit. I just looked in the .ipynb
you provided and it seems you may have downloaded the file from the URL and renamed it auto.csv
So your code should be after running the ‘download’ cell:
import pandas as pd
df = pd.read_csv("auto.csv")
Or if you want to do it the ‘foolproof’ way I describe, where you download the file first to your own local machine and then drag and drop it in the file browser in the directory next to your running notebook, then you’d still use the file name of auto.csv
. Of course, they may have disabled drag-and-drop in the Coursera JupyterLite. I don’t have access to test if they somehow blocked the ‘foolproof’ way. That shouldn’t matter because it looked like the ‘download’ cell worked in the first screenshot you provided. So after running that sell run the code I’ve urged you to run twice now, df = pd.read_csv("auto.csv")
, and Pandas will read the data from where it is stored in the virtual filesystem running in your browser after auto.csv
was downloaded via that code that reads await download(file_path, "auto.csv")
. )
Note that in the screenshot you originally provided, the file auto.csv
is shown listed in the same directory with your notebook. So just read the data in now with df = pd.read_csv("auto.csv")
.
That way, when you run the next cell in your notebook, which is the code cell below, it will work now and show the first five rows of the dataframe:
# show the first 5 rows using dataframe.head() method
print("The first 5 rows of the dataframe")
df.head(5)
No. Once you have the file auto.csv
in the directory next to your notebook (via the ‘foolproof’ way or the ‘download’ code route), I’m saying just what I’ve said several times now:
In place of the cell where in your notebook you have df = pd.read_csv(filepath, header=None)
, run the following code:
import pandas as pd
df = pd.read_csv("auto.csv")
Or,
import pandas as pd
df = pd.read_csv("auto.csv", header=None)
There’s no need for a filepath because, in lieu of an absolute file path, your notebook will look first in the directory where it is running. And if it sees the file there, it will use it. So just put the file there and use a relative file path. If you want to be dogmatic about it you can even try df = pd.read_csv("./auto.csv", header=None)
. The dot signals to look in the same directory where the current working directory is already located, so that "./auto.csv"
is a full path that happens to be a full relative path. But usually just "auto.csv"
is sufficient.