import pandas as pd
df=pd.read_excel(r'student.xlsx',sheet_name='Sheet1')
df1=pd.read_excel(r'class.xlsx',sheet_name='Sheet1')
print(len(df),len(df1))
count = 0
for i in range(len(df1)):
he = ''
for j in range(len(df)):
try:
#print(df1.iloc[j,0],df1.iloc[j,0])
q = df.iloc[j, 9].count(df1.iloc[i, 0])
if q != 0:
if he == '':
he = df.iloc[j, 0]
else:
he = he + "," + df.iloc[j, 0]
# print(df1.iloc[i,0],he)
df1.iloc[i, 3] = he
except:
pass
#print(i)
if (i % 100 == 9):
df1.to_excel(r'grade.xlsx')
读取student.xlsx和class.xlsx 文件内容,获取每个学生对应班级的成绩,保存成绩到grade.xlsx文件里面