简体   繁体   English

如何在streamlit中从用户读取csv文件并转换为pandas数据帧

[英]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.

相关问题 如何在 Streamlit 中将 Pandas DataFrame 下载到 CSV 文件 - How do I download a Pandas DataFrame to a CSV File in Streamlit 汉字从 pandas dataframe 到 CSV 与 Streamlit - Chinese characters from pandas dataframe to CSV with Streamlit 将从csv文件读取的pandas数据框列中的HTML转换为纯文本 - Converting HTML in a pandas dataframe column which was read from a csv file to Plain text 如何使用pandas.read_csv将CSV文件中的数据插入数据框? - How can I insert data from a CSV file into a dataframe using pandas.read_csv? 从 csv 文件中读取 Pandas dataframe 并转换为 ZA7F5F35426B927411173231B5632 类型 - Read Pandas dataframe from csv file and convert to Python types 如何停止Python read_csv数据框转换日期 - How to stop Python read_csv Dataframe from converting Dates When converting a pandas dataframe to csv, how can i seperate the headers of the dataframe into different columns of the csv-file? - When converting a pandas dataframe to csv, how can i seperate the headers of the dataframe into different columns of the csv-file? 将熊猫数据框转换为 csv - Converting pandas dataframe to csv 如何使用Pandas DataFrame读取CSV文件包含图像的像素值 - How to read csv file contains pixels value of images with Pandas DataFrame 如何在 Pandas 中将 csv 文件作为系列而不是数据帧读取? - How to read a csv file as series instead of dataframe in pandas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM