Python. Пожалуйста помогите понять в чём ошибка
Задание в котором есть файл с данными о студентах которые прошли тест, нужно добавить столбец в котором будет число полученное делением потраченного времени на на сумму балов за ответы на вопросы и отсортировать от самого большого числа к самому низкому.
Для этого задания решил воспользоваться pandas.
Код который написал ->
import pandas as pd
with open('marks.csv', "r+") as file:
data = file.read()
with open('marks_new.csv', "wt+") as file:
file.seek(0)
file.write('ПІБ, початок часу, кінець часу, затрачений час, Питання 1, Питання 2, Питання 3, Питання 4, Питання 6, Питання 6, Питання 7, Питання 8, Питання 9, Питання 10, Питання 11, Питання 12, Питання 13, Питання 14, Питання 15, Питання 16, Питання 17, Питання 18, Питання 19, Питання 20, Питання 21\n' + data)
students_df = pd.read_csv('marks_new.csv')
students_df['оцінка\час'] = (students_df['Питання 1'] + students_df['Питання 2'] + students_df['Питання 3'] + students_df['Питання 4'] + students_df['Питання 5'] + students_df['Питання 6'] + students_df['Питання 7'] + students_df['Питання 8'] + students_df['Питання 9'] + students_df['Питання 10'] + students_df['Питання 11'] + students_df['Питання 12'] + students_df['Питання 13'] + students_df['Питання 14'] + students_df['Питання 15'] + students_df['Питання 16'] + students_df['Питання 18'] + students_df['Питання 19'] + students_df['Питання 20'] + students_df['Питання 21']) / students_df['затрачений час']
print(students_df)
В итоге даже не дошёл до сортировки, выдаёт ошибку на строке
students_df['оцінка\час'].....
Ошибка под названием
Питання 1
Ответы (1 шт):
Автор решения: Василий Котеков
→ Ссылка
with open('marks.lab6.csv', "r+") as file:
data = file.read()
with open('marks_new.csv', "wt+") as file:
file.seek(0)
file.write('ПІБ,початок часу,кінець часу,затрачений час,Питання 1,Питання 2,Питання 3,Питання 4,Питання 5,Питання 6,Питання 7,Питання 8,Питання 9,Питання 10,Питання 11,Питання 12,Питання 13,Питання 14,Питання 15,Питання 16,Питання 17,Питання 18,Питання 19,Питання 20,Питання 21\n' + data)
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
students_df = pd.read_csv('marks_new.csv')
students_df['Питання 1'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 1']]
students_df['Питання 2'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 2']]
students_df['Питання 3'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 3']]
students_df['Питання 4'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 4']]
students_df['Питання 5'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 5']]
students_df['Питання 6'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 6']]
students_df['Питання 7'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 7']]
students_df['Питання 8'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 8']]
students_df['Питання 9'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 9']]
students_df['Питання 10'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 10']]
students_df['Питання 11'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 11']]
students_df['Питання 12'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 12']]
students_df['Питання 13'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 13']]
students_df['Питання 14'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 14']]
students_df['Питання 15'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 15']]
students_df['Питання 16'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 16']]
students_df['Питання 17'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 17']]
students_df['Питання 18'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 18']]
students_df['Питання 19'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 19']]
students_df['Питання 20'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 20']]
students_df['Питання 21'] = [x.replace(',', '.').replace('-', '0') for x in students_df['Питання 21']]
students_df['затрачений час'] = [x.replace('хв', '').replace('сек', '') for x in students_df['затрачений час']]
students_df['затрачений час'] = [x.split(" ")[0] for x in students_df['затрачений час']]
students_df['оцінка\час'] = (students_df['Питання 1'].astype(float) + students_df['Питання 2'].astype(float) + students_df['Питання 3'].astype(float) + students_df['Питання 4'].astype(float) + students_df['Питання 5'].astype(float) + students_df['Питання 6'].astype(float) + students_df['Питання 7'].astype(float) + students_df['Питання 8'].astype(float) + students_df['Питання 9'].astype(float) + students_df['Питання 10'].astype(float) + students_df['Питання 11'].astype(float) + students_df['Питання 12'].astype(float) + students_df['Питання 13'].astype(float) + students_df['Питання 14'].astype(float) + students_df['Питання 15'].astype(float) + students_df['Питання 16'].astype(float) + students_df['Питання 17'].astype(float) + students_df['Питання 18'].astype(float) + students_df['Питання 19'].astype(float) + students_df['Питання 20'].astype(float) + students_df['Питання 21'].astype(float)) / students_df['затрачений час'].astype(float)
students_df = students_df.sort_values('оцінка\час')
students_df.reset_index(drop= True , inplace= True )
students_df.head().to_csv("Answer.txt", mode="a+", header=False, sep='|')
Программа исправлена и дописана, огромная благодарность CrazyElf


