Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from openpyxl import load_workbook, Workbook
- defaulters = []
- MIN_PERCENT = 70
- wb = load_workbook(filename="input.xlsx")
- sheet = wb.active
- total_days = sheet.max_column - 2
- for row in sheet.iter_rows(min_row=2):
- attendance = sum([i.value for i in row[2:]])
- if attendance < total_days * (MIN_PERCENT / 100):
- defaulters.append(
- [
- row[0].value,
- row[1].value,
- attendance,
- total_days,
- round((attendance / total_days) * 100, 2),
- ]
- )
- wb = Workbook()
- sheet = wb.active
- headers = ["Roll", "Name", "Count", "Total", "perc"]
- for i, h in enumerate(headers, start=1):
- sheet.cell(row=1, column=i).value = h
- for i, row in enumerate(defaulters, start=2):
- for j, col in enumerate(row, start=1):
- sheet.cell(row=i, column=j).value = col
- wb.save("defaulter.xlsx")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement