Uploading CSV and excel files

@Fabio Hi, you can just use st.file_uploader(“the notice you want to tell”) to finish upload function.
both csv and xls or xlsx file can be uploaded.
example:

import pandas as pd
import streamlit as st
uploaded_file = st.file_uploader(“Choose a file”)
if uploaded_file is not None:
#read csv
df1=pd.read_csv(uploaded_file)

   #read xls or xlsx
   df1=pd.read_excel(uploaded_file)

else:
st.warning(“you need to upload a csv or excel file.”)

if you want to capture the file name of uploaded, you can write code like this:
filename=uploaded_file.name

1 Like