Issue
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
data = pd.read_csv(uploaded_file)
#Get overview of data
st.write(data.head())
else:
data = pd.read_excel(uploaded_file)
#Get overview of data
st.write(data.head())
It gives me error if I upload excel file, and I understand why. I have to check the uploaded file's extension before reading it in csv or excel format. HOW to check the uploaded file's extension?
Solution
If I understood You correctly, there is a simple option.
file_split = uploaded_file.split('.')
file_extension = '' if len(file_split) != 2 else file_split[1]
Answered By - valart
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.