question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pandas.read_csv("iris.csv") FileNotFound

See original GitHub issue

Description

Pandas read_csv gave FileNotFound error on example file iris.csv. I’m hope this is not a silly user error and I’m sorry in advance if it is.

Screenshot 2021-06-01 at 17 02 46

Reproduce

  • Create new notebook in examples folder
  • import pandas as pd
  • pd.read_csv("iris.csv")

Expected behavior

Load and display the content of iris.csv on screen

Context

  • Operating System and version:
  • MacOS 11.2.3
  • MacBook Air (M1, 2020)
  • Apple M1 chip
  • Browser and version: Brave Version 1.24.84 Chromium: 90.0.4430.93 (Official Build) (arm64)
  • JupyterLite version: can’t find version number but I did this today (2021/06/01) using JupyterLite for the first time
Browser Output
Dispose worker for kernel 7f928317-a338-41fb-9c00-6c1d041909fd
default.js:1228 Connection lost, reconnecting in 0 seconds.
_reconnect @ default.js:1228
reconnect @ default.js:516
restart @ default.js:487
async function (async)
restart @ default.js:484
restartKernel @ sessioncontext.js:298
restart @ sessioncontext.js:758
async function (async)
restart @ sessioncontext.js:733
onClick @ toolbar.js:343
y.createElement.onMouseDown @ toolbar.js:402
Be @ react-dom.production.min.js:52
Ke @ react-dom.production.min.js:52
(anonymous) @ react-dom.production.min.js:53
xr @ react-dom.production.min.js:100
Cr @ react-dom.production.min.js:101
(anonymous) @ react-dom.production.min.js:113
De @ react-dom.production.min.js:292
(anonymous) @ react-dom.production.min.js:50
Lr @ react-dom.production.min.js:105
Zn @ react-dom.production.min.js:75
Jn @ react-dom.production.min.js:74
n.unstable_runWithPriority @ scheduler.production.min.js:18
Bl @ react-dom.production.min.js:122
Me @ react-dom.production.min.js:292
Xn @ react-dom.production.min.js:73
pyodide.asm.js:9 Python initialization complete
pyodide.js:146 Loading matplotlib, cycler, six, kiwisolver, numpy, pillow, pyparsing, python-dateutil, pytz
pyodide.js:196 Loading matplotlib from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/matplotlib.js
pyodide.js:196 Loading cycler from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/cycler.js
pyodide.js:196 Loading six from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/six.js
pyodide.js:196 Loading kiwisolver from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/kiwisolver.js
pyodide.js:196 Loading numpy from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/numpy.js
pyodide.js:196 Loading pillow from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pillow.js
pyodide.js:196 Loading pyparsing from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pyparsing.js
pyodide.js:196 Loading python-dateutil from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/python-dateutil.js
pyodide.js:196 Loading pytz from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pytz.js
pyodide.js:252 Loaded matplotlib, cycler, six, kiwisolver, numpy, pillow, pyparsing, python-dateutil, pytz
pyodide.js:146 Loading micropip, pyparsing, packaging
pyodide.js:196 Loading micropip from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/micropip.js
pyodide.js:184 pyparsing already loaded from default channel
pyodide.js:196 Loading packaging from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/packaging.js
pyodide.js:252 Loaded micropip, pyparsing, packaging
8ebb3553-36cc-44b7-9b0c-539a2f402d28:29 Pyolite kernel initialized, version 0.1.0
8ebb3553-36cc-44b7-9b0c-539a2f402d28:63 Inside worker {code: "import pandas as pd"}
pyodide.js:146 Loading pandas, numpy, python-dateutil, pytz
pyodide.js:196 Loading pandas from https://cdn.jsdelivr.net/pyodide/v0.17.0/full/pandas.js
pyodide.js:184 numpy already loaded from default channel
pyodide.js:184 python-dateutil already loaded from default channel
pyodide.js:184 pytz already loaded from default channel
pyodide.js:252 Loaded pandas, numpy, python-dateutil, pytz
8ebb3553-36cc-44b7-9b0c-539a2f402d28:63 Inside worker {code: "pd.read_csv("iris.csv")"}code: "pd.read_csv(\"iris.csv\")"__proto__: Object

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
jtpiocommented, Jun 4, 2021

Thanks @mklilley for trying it out 👍

Looks like it’s related to not being able to do raw network request using the Python standard library.

As a workaround, something like the following could do the job maybe?

import pandas as pd
from js import fetch

URL = "https://support.staffbase.com/hc/en-us/article_attachments/360009197031/username.csv"

res = await fetch(URL)
text = await res.text()

filename = 'data.csv'

with open(filename, 'w') as f:
    f.write(text)

data = pd.read_csv(filename, sep=';')
data

image

2reactions
rthcommented, Jan 31, 2022

For those who find this and are trying to work with a binary file, here is an example of unpickling a file from a URL

Since Pyodide 0.19 (included in the latest JupyterLite) there is also the pyodide.http.pyfetch function aiming to make it a bit easier to work with JS fetch from Python. With it the above example would be,

from pyodide.http import pyfetch
import pickle, numpy

URL = "https://raw.githubusercontent.com/jmshea/digicom-jupyter/main/content/signals.pkl"
res = await pyfetch(URL)
stream = await res.bytes()

data = pickle.loads(stream)
data
Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.read_csv FileNotFoundError: File b'\xe2\x80\xaa<etc ...
The error "FileNotFoundError: File b'C:Users\\user\\Desktop\\tutorial.csv' does not exist" comes up when I tried to combine it. Removing the ...
Read more >
Error - unable to read the csv file in pandas
Seems that pandas is not able to find the file, check if the file 'data.csv' is in same directory as the python script...
Read more >
Read CSV files using Pandas - With Examples
The pandas read_csv() function is used to read a CSV file into a dataframe. With it, you can also customize how you'd like...
Read more >
Importing and viewing the Iris dataset using pandas
The pandas read_csv function loads delimited data from a file, URL or file-like object using the comma as the default delimiter and creates...
Read more >
[Solved]-Jupyter is not finding the "iris" file-Pandas,Python
The best practice for reading a CSV file in python is to add "r" before the directory, as mentioned in the example below....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found