Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EmptyDataError: No columns to parse from file about streamlit

I am using streamlit version v0.68 and currently working on CSV file for data analysis.

st.title('Report Analysis')
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
    data = pd.read_csv(uploaded_file, low_memory=False)
    st.write(data.shape)

First it works, but if I rerun the program in my localhost it gives me the error:

EmptyDataError: No columns to parse from file
Traceback:

File "D:\My Programs\Projects\ReportAnalysis\venv\lib\site-packages\streamlit\script_runner.py", line 324, in _run_script
    exec(code, module.__dict__)
File "D:\My Programs\Projects\ReportAnalysis\epl\app.py", line 9, in <module>
    data = pd.read_csv(uploaded_file, low_memory=False)
File "D:\My Programs\Projects\ReportAnalysis\venv\lib\site-packages\pandas\io\parsers.py", line 686, in read_csv
    return _read(filepath_or_buffer, kwds)
File "D:\My Programs\Projects\ReportAnalysis\venv\lib\site-packages\pandas\io\parsers.py", line 452, in _read
    parser = TextFileReader(fp_or_buf, **kwds)
File "D:\My Programs\Projects\ReportAnalysis\venv\lib\site-packages\pandas\io\parsers.py", line 946, in __init__
    self._make_engine(self.engine)
File "D:\My Programs\Projects\ReportAnalysis\venv\lib\site-packages\pandas\io\parsers.py", line 1178, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
File "D:\My Programs\Projects\ReportAnalysis\venv\lib\site-packages\pandas\io\parsers.py", line 2008, in __init__
    self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 540, in pandas._libs.parsers.TextReader.__cinit__

How to handle this error?

like image 406
Swarnim Kumar Avatar asked Oct 14 '20 06:10

Swarnim Kumar


People also ask

How to resolve the error ‘emptydataerror’ in Panda Dataframe?

How to resolve the error ‘EmptyDataError’:No column to parse from file while reading data into a Panda Dataframe. when empty data or header is encountered then this exception is thrown. Recheck quality of the input file you are reading. Your csv format is proper (remember sometimes comma create issues)

Is it possible to go back to an older version of streamlit?

As a work-around, you can always go back to an older version, e.g. 0.66, using: pip install streamlit=0.66 Show activity on this post.

Why does read_CSV return no rows?

Since pd.read_csv depletes the buffer, the second time you call read_csv will return no rows. Adding a seek (0) to reset the buffer worked for me.


1 Answers

According to this post from the Streamlit community page, it is because they are returning the same buffer on the second time the app refreshes. Since pd.read_csv depletes the buffer, the second time you call read_csv will return no rows.

Adding a seek(0) to reset the buffer worked for me.

e.g.

st.title('Report Analysis')
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
    uploaded_file.seek(0)
    data = pd.read_csv(uploaded_file, low_memory=False)
    st.write(data.shape)
like image 137
Mike Avatar answered Oct 02 '22 17:10

Mike