Abhiram C D
Abhiram C D

Reputation: 127

How to read csv file from user in streamlit and converting to pandas dataframe

I want to read some spectral data to my streamlit application. Each row in the file is a spectrum (different intensity values). So, I used st.fileuploader

spectra = st.file_uploader("upload file", type={"csv", "txt"})
spectra = pd.DataFrame(spectra_1_file)
st.write(spectra_1)

Now, I am getting only one row of data on each column I have each spectrum as comma-separated. I need to convert the input from the user to a similar fashion of pd.csv_read. Because, when I was using it, I was able to get a proper pandas data frame. I tried different methods to read. But, never got the proper way. this was the closest I could get.

Thank you in advance.

Upvotes: 4

Views: 14463

Answers (2)

Fairouz
Fairouz

Reputation: 1

By using Pandas and Streamlit, you can read and upload your CSV file into your localhost.

data = pd.read_csv("csv_practice.csv") #path folder of the data file
st.write(data) #displays the table of data

Upvotes: 0

queste
queste

Reputation: 310

spectra = st.file_uploader("upload file", type={"csv", "txt"})
if spectra is not None:
    spectra_df = pd.read_csv(spectra)
st.write(spectra_df)

Upvotes: 5

Related Questions