import pandas as pd
import random
import openpyxl
fn = r'C:\Users\Junze\Desktop\f21010516畅钧泽\studentAttendance.xlsx'
wb = openpyxl.load_workbook(fn)
ws = wb.worksheets[0]
ws['G7'] = 'Score'
ws['H7'] = 'Grade'
for r in range(8,90):
for i in range(0,81):
a = random.randint(70,90)
ws.cell(row=r, column=7, value=a)
ws['G56'] = '90'
excel = pd.read_excel('C:/Users/Junze/Desktop/f21010516畅钧泽/studentAttendance.xlsx')
print(excel)
excel = excel.set_index('arre.index')
excel['Grade'] = excel.apply(lambda x: "优"
if x.Grade >= excel['Grade'].quantile(q=0.75)
else
("中"
if x.Grade <= excel['Grade'].quantile(q=0.25)
else
"良"
), axis = 1
)
date = []
excel_lexel = [excel['Grade'] == '优']
date = excel_lexel
print(pd.DataFrame(date, columns=['Student No', 'Name', 'Grade']))
excel.to_excel('F21010516-畅钧泽.xls')
问题是"None of ['arre.index'] are in the columns"