Skip to content

Instantly share code, notes, and snippets.

@mkhorasani
Created September 7, 2021 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkhorasani/82126d02166fbe6e26b494a443c75341 to your computer and use it in GitHub Desktop.
Save mkhorasani/82126d02166fbe6e26b494a443c75341 to your computer and use it in GitHub Desktop.
def file_upload(name):
uploaded_file = st.sidebar.file_uploader('%s' % (name),key='%s' % (name),accept_multiple_files=False)
content = False
if uploaded_file is not None:
try:
uploaded_df = pd.read_csv(uploaded_file)
content = True
return content, uploaded_df
except:
try:
uploaded_df = pd.read_excel(uploaded_file)
content = True
return content, uploaded_df
except:
st.error('Please ensure file is .csv or .xlsx format and/or reupload file')
return content, None
else:
return content, None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment