I built a streamlit
app where one can upload csv, xls, xlsx files.
And I’m loading the uploaded files using below functions load_data
, load_excel
# Load dataset
@st.cache(allow_output_mutation=True)
def load_data(data_file):
# Read csv using pandas
data = pd.read_csv(data_file)
# Copy dataframe
df = data.copy()
# return dataframe
return df
@st.cache(allow_output_mutation=True)
def load_excel(data_file):
# read excel using pandas
exls = pd.read_excel(data_file, sheet_name=None)
# make a copy of df
xls = exls.copy()
# extract sheet names to a list
sheet_names = list(xls.keys())
# return datframe & sheet names
return xls, sheet_names
I’m using the below code to load the uploaded files. And it was working well.
data_file = st.file_uploader("Upload File",type=["csv", "xls", "xlsx"])
if data_file is not None:
# cvs files only
if data_file.name.endswith("csv"):
# Read uploaded file
raw_data = stu.load_data(data_file)
else:
# get excel and sheet names
xls, sheet_names = stu.load_excel(data_file)
# Dropdown to select sheet name
sheet = st.selectbox("Select a Sheet", sheet_names)
# Load selected sheet
raw_data = xls[sheet]
This app is deployed in Domino. It was working fine. But from last couple of days its throwing an error for csv or xls files. The environment is not changed, and none of the libraries is updated/added. It’s working fine in the local environment. Currently, I’m not sure what is causing this error or on how to fix this issue? Below is the complete trace back
for xls and csv files. Can someone shed some light on what this issue is and how can fix this?
Excel(xls) file traceback
TypeError: expected str, bytes or os.PathLike object, not NoneType
Traceback:
File "/usr/local/lib/python3.6/dist-packages/streamlit/script_runner.py", line 354, in _run_script
exec(code, module.__dict__)
File "/mnt/app.py", line 122, in <module>
xls, sheet_names = stu.load_excel(data_file)
File "/usr/local/lib/python3.6/dist-packages/streamlit/legacy_caching/caching.py", line 543, in wrapped_func
return get_or_create_cached_value()
File "/usr/local/lib/python3.6/dist-packages/streamlit/legacy_caching/caching.py", line 527, in get_or_create_cached_value
return_value = func(*args, **kwargs)
File "/mnt/src/streamlit_utils.py", line 113, in load_excel
exls = pd.read_excel(data_file, sheet_name=None)
File "/usr/local/lib/python3.6/dist-packages/pandas/util/_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/excel/_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/excel/_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/excel/_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/excel/_base.py", line 351, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/excel/_xlrd.py", line 35, in load_workbook
return open_workbook(file_contents=data)
File "/usr/local/lib/python3.6/dist-packages/xlrd/__init__.py", line 110, in open_workbook
filename = os.path.expanduser(filename)
File "/usr/lib/python3.6/posixpath.py", line 235, in expanduser
path = os.fspath(path)
CSV file traceback
EmptyDataError: No columns to parse from file
Traceback:
File "/usr/local/lib/python3.6/dist-packages/streamlit/script_runner.py", line 354, in _run_script
exec(code, module.__dict__)
File "/mnt/app.py", line 118, in <module>
df = stu.load_data(data_file)
File "/usr/local/lib/python3.6/dist-packages/streamlit/legacy_caching/caching.py", line 543, in wrapped_func
return get_or_create_cached_value()
File "/usr/local/lib/python3.6/dist-packages/streamlit/legacy_caching/caching.py", line 527, in get_or_create_cached_value
return_value = func(*args, **kwargs)
File "/mnt/src/streamlit_utils.py", line 82, in load_data
data = pd.read_csv(data_file)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 688, in read_csv
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 454, in _read
parser = TextFileReader(fp_or_buf, **kwds)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 948, in __init__
self._make_engine(self.engine)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 1180, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py", line 2010, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas/_libs/parsers.pyx", line 540, in pandas._libs.parsers.TextReader.__cinit__