Python 两个数据帧的平均结果

Python 两个数据帧的平均结果,python,pandas,numpy,Python,Pandas,Numpy,在这个主题上,我在这里查看了有关stackoverflow的各种示例,但non对我很有用 我的案例是两个数据帧(学生分数)。我应该算出这两个数字的平均值,然后把结果还给大家。当我删除包含姓名和其他学生详细信息的列时效果很好,当它们被包含时会崩溃 这是我的一部分 elif self.exam_combo.currentText()=="2": df2 = QFileDialog.getOpenFileName(MainWindow, 'Upload marks', os.geten

在这个主题上,我在这里查看了有关stackoverflow的各种示例,但non对我很有用

我的案例是两个数据帧(学生分数)。我应该算出这两个数字的平均值,然后把结果还给大家。当我删除包含姓名和其他学生详细信息的列时效果很好,当它们被包含时会崩溃

这是我的一部分

elif self.exam_combo.currentText()=="2":
        df2 = QFileDialog.getOpenFileName(MainWindow, 'Upload marks', os.getenv('HOME'), 'CSV(*.csv)')
        path = df2[0]
        df3 = pd.read_csv(path)
        QMessageBox.information(MainWindow,"Successfull","Choose the last set of marks to upload.")
        df4 = QFileDialog.getOpenFileName(MainWindow, 'Upload marks', os.getenv('HOME'), 'CSV(*.csv)')
        path = df4[0]
        df5 = pd.read_csv(path)

        dfs = [df3, df5]
        df = pd.DataFrame(np.array([x.to_numpy() for x in dfs]).mean(axis=0), index=df3.index, columns=df3.columns)
它给出了一个错误

Traceback (most recent call last):
  File "D:\Python\PyQt5\Proper_1.py", line 1557, in upload_marks
df = pd.DataFrame(np.array([x.to_numpy() for x in dfs]).mean(axis=0), index=df3.index, columns=df3.columns)
  File "C:\Users\Links Net\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\core\_methods.py", line 153, in _mean
    ret = um.true_divide(
TypeError: unsupported operand type(s) for /: 'str' and 'int'
我认为这是由于字符串和整数的混合使系统平均。 任何人都可以帮忙。我也试过了

df_concat.groupby(level=0).mean()

使用:

dfs = [df3, df5]
#select only numeric columns
dfs = [x.select_dtypes(np.number) for x in dfs]
#join together with mean per index
df = pd.concat(dfs).mean(axis=0)
我和它一起工作

dfs=pd.concat([df3,df5]).groupby(["STREAM", "ADM", "NAME", "KCPE" ]). mean() 

什么是
print(df3.dtypes)
print(df5.dtypes)
?似乎有些列不是numericSTREAM对象ADM int64 NAME对象KCPE int64 ENG int64 KIS int64 dtype:object STREAM对象ADM int64 NAME对象KCPE int64 ENG int64 KIS int64 dtype:object所以它的意思是
STREAM
NAME
列是对象、字符串,那么,它们的可能含义是什么呢?是否需要删除此列?或者以不同的方式处理?是的,有些列不是数字。我只需要学生分数的平均列,其余的是名称、rollno、stream等,它们是字符串值Show我要删除吗?如何进行不同的处理?给出索引器错误:元组索引超出范围