val保存每个模型;LR统计请假m名单次数代码
parent
b1ad75ee16
commit
d3262fdc17
@ -0,0 +1,16 @@
|
||||
import pandas as pd
|
||||
|
||||
# 读取原始Excel文件的所有sheet
|
||||
excel_file = pd.ExcelFile('data/LeaveRecord.xlsx')
|
||||
df = pd.concat([excel_file.parse(sheet_name) for sheet_name in excel_file.sheet_names])
|
||||
|
||||
# 统计每个学生的请假次数和姓名
|
||||
student_counts = df.groupby('学号').size().reset_index(name='请假次数')
|
||||
student_names = df.groupby('学号')['姓名'].unique().reset_index()
|
||||
student_counts['姓名'] = student_names['姓名'].apply(lambda x: ','.join(x))
|
||||
|
||||
# 判断是否错误
|
||||
student_counts['是否错误'] = student_counts['姓名'].apply(lambda x: 1 if len(x.split(',')) > 1 else 0)
|
||||
|
||||
# 保存结果到新的Excel文件
|
||||
student_counts.to_excel('output_LR_1.xlsx', index=False)
|
||||
@ -0,0 +1,19 @@
|
||||
import pandas as pd
|
||||
|
||||
# 读取原始Excel文件
|
||||
df = pd.read_excel('data/LeaveRecord.xlsx', sheet_name=None)
|
||||
|
||||
# 创建一个空的DataFrame来保存统计结果
|
||||
result_df = pd.DataFrame(columns=['学号', '请假次数'])
|
||||
|
||||
# 遍历每个sheet
|
||||
for sheet_name, sheet_data in df.items():
|
||||
# 统计每个学生的请假次数
|
||||
student_counts = sheet_data['学号'].value_counts().reset_index()
|
||||
student_counts.columns = ['学号', '请假次数']
|
||||
|
||||
# 将统计结果添加到结果DataFrame中
|
||||
result_df = pd.concat([result_df, student_counts], ignore_index=True)
|
||||
|
||||
# 保存结果DataFrame到新的Excel文件
|
||||
result_df.to_excel('output_LR.xlsx', index=False)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue