How to get dataframe in excel to a variable using file uploader

i have a dataframe in excel file. I want to load that to a variable using file uploader. When i read the o/p from file uploder, looks like its byte i.o and when i use pd.DataFrame on top of it. It does not give intended result. Though if i use st.table(), i am able to see results as table

2 Likes

Hey @karthico, Welcome to the forums! :slight_smile:

Iโ€™ve just tried it using this example and it works perfectly with st.table and st.dataframe

Try this after running pip install xlrd

import streamlit as st
import pandas as pd

uploaded_file = st.file_uploader("Choose a XLSX file", type="xlsx")

if uploaded_file:
    df = pd.read_excel(uploaded_file)

    st.dataframe(df)
    st.table(df)
2 Likes

hey buddy, thanks a lot this works. Also any idea like what are the file types we can upload.

Hey @karthico - you should be able to upload files of any type (though you can limit which file extensions the file uploader will accept with the optional type argument).

The st.file_uploader widget returns each uploaded file as either a string (if the file is just text) or a BytesIO binary blob (for all other files). In the latter case, youโ€™ll need to have code that can work with the fileโ€™s binary format, but youโ€™re not limited in what you can do with it.

3 Likes

Hey @arraydude , tried this same code but faced the below error.

I also ran pip install xlrd and the requirement was already satisfied.

Getting this error after running the code:

Please helpโ€ฆ!!