小编Pyt*_*ner的帖子

数据预处理后从 Streamlit Web 应用程序下载数据帧时出错

所需的任务是在 Streamlit 上部署数据预处理 Web 应用程序,用户可以在其中上传原始数据帧并下载处理后的数据帧。我正在尝试下载已完成数据预处理(例如缺失值插补)的文件,但出现如下错误:

RuntimeError: Invalid binary data format: <class 'pandas.core.frame.DataFrame'>
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决这个问题。请帮助我,因为我是 python 和 StreamLit 的新手。代码是

import streamlit as st
import pandas as pd
import os
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
temp='\\temp.csv'
path=os.getcwd()
path=path+temp

def upload_csv(zxc):
    if zxc:
        df=pd.read_csv(zxc)
        st.dataframe(df)
        df.to_csv(path,index=False)
        return df
    

def upload_xlsx(zxc):
    if zxc:
        df=pd.read_excel(zxc)
        st.dataframe(df)
        df.to_csv(path,index=False)
        return df

def mvt_mean(df):
    new_df=df.fillna(df.mean())
    new_df=new_df.fillna(df.select_dtypes(include='object').mode().iloc[0])
    st.dataframe(new_df)
    return new_df


def mvt_median(df):
    new_df=df.fillna(df.median())
    new_df=new_df.fillna(df.select_dtypes(include='object').mode().iloc[0])
    st.dataframe(new_df)
    return new_df

def mvt_mode(df):
    new_df=df.fillna(df.select_dtypes(include='object').mode().iloc[0])
    st.dataframe(new_df)
    return new_df

def export_data():
    with open('temp.csv','r+') …
Run Code Online (Sandbox Code Playgroud)

python download file-handling streamlit data-preprocessing

5
推荐指数
1
解决办法
4726
查看次数