EmptyDataError: No columns to parse from file

Anyone know why you get:

EmptyDataError: No columns to parse from file

when i run:

if uploaded_file is not None:

        df = pd.read_csv(uploaded_file)

Are you able to do read the csv you uploaded with pd.read_csv when the file is stored locally ? (ie. in a notebook for example). It could be that you uploaded a file that can’t be read with pandas. Keep an eye on this post, the user seems to have the same issue as you.

Locally it works perfectly. When I deploy the app to Heroku. The app builds, runs and even completes the upload of the csv file. I read the Stackoverflow thread you linked…Same same for me. May change the dependency back to streamlit 0.66 in requirements. But any subsequent operations on the file and it throws :

EmptyDataError: No columns to parse from file

Traceback:

File "/app/.heroku/python/lib/python3.6/site-packages/streamlit/script_runner.py", line 324, in _run_script
    exec(code, module.__dict__)File "/app/myappV3.py", line 239, in <module>
    main()File "/app/myappV3.py", line 197, in main
    df,columns = upload_csv()File "/app/myappV3.py", line 174, in upload_csv
    df = pd.read_csv(uploaded_file)File "/app/.heroku/python/lib/python3.6/site-packages/pandas/io/parsers.py", line 686, in read_csv
    return _read(filepath_or_buffer, kwds)File "/app/.heroku/python/lib/python3.6/site-packages/pandas/io/parsers.py", line 452, in _read
    parser = TextFileReader(fp_or_buf, **kwds)File "/app/.heroku/python/lib/python3.6/site-packages/pandas/io/parsers.py", line 936, in __init__
    self._make_engine(self.engine)File "/app/.heroku/python/lib/python3.6/site-packages/pandas/io/parsers.py", line 1168, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)File "/app/.heroku/python/lib/python3.6/site-packages/pandas/io/parsers.py", line 1998, in __init__
    self._reader = parsers.TextReader(src, **kwds)File "pandas/_libs/parsers.pyx", line 540, in pandas._libs.parsers.TextReader.__cinit__

Just so I’m clear, your app works locally with 0.68, but deploying to Heroku it only works with 0.66?

It’s likely that you need to reset your buffer with uploaded_file.seek(0).

Previously we were creating a new buffer for you each time we reran. To optimize, we are returning the same buffer on rerun. Unfortunately, this means that if you’ve already read the buffer, you’ll need to reset after. If you use .getValue() , there’s no need to seek . Unfortunately for file uploader pandas.read_csv does a read() which will require a buffer reset.

4 Likes

Probably worth adding this exact error message to our docs, to give it more visibility.

3 Likes

Ok thank you I will try to implement your suggestions.

Facing the same issue repeatedly
implemented all solutions given still facing the same error
Please provide proper solution

seek(0) works perfectly

1 Like