On this subject, I have looked at various examples here on stackoverflow but non has worked for me.
My case is of two dataframes(STUDENTS MARKS). I should be working out the average of the two and give back the result. It works well when I remove the columns with names and other students details and crashes when they are included.
This is part of what I have.
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)
It gives an error.
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'
I think this comes due to the mixup of strings and integers for the system to average. Anybody to help out. I've also tried
df_concat.groupby(level=0).mean()