[英]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
所以,我使用了
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
.我需要将来自用户的输入转换为类似的
pd.csv_read
。 Because, when I was using it, I was able to get a proper pandas data frame.因为,当我使用它时,我能够得到一个合适的 Pandas 数据框。 I tried different methods to read.
我尝试了不同的阅读方法。 But, never got the proper way.
但是,从来没有得到正确的方法。 this was the closest I could get.
这是我能得到的最接近的。
Thank you in advance.先感谢您。
spectra = st.file_uploader("upload file", type={"csv", "txt"})
if spectra is not None:
spectra_df = pd.read_csv(spectra)
st.write(spectra_df)
By using Pandas and Streamlit, you can read and upload your CSV file into your localhost.通过使用 Pandas 和 Streamlit,您可以读取您的 CSV 文件并将其上传到您的本地主机。
data = pd.read_csv("csv_practice.csv") #path folder of the data file
st.write(data) #displays the table of data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.