Requirements:
Put the data inside the App_student.xls,
1, if this line of data has garbled (and contains?), then delete
2, plus a column, whether graduation
3, if the class is a Scorpio, graduation this column is written as a graduate
4, the other classes are written not graduated
Raw DATA:
implementation:
ImportXlrd,xlwtexcel_name='App_student.xls'defDelete_messy_code (Excel_name):#Remove garbled charactersBook =Xlrd.open_workbook (excel_name) sheet=book.sheet_by_index (0) data= [] forIinchRange (sheet.nrows):if '?' inchSTR (sheet.row_values (i)):#add only data that is not garbled to data[] Continue Else: Data.append (Sheet.row_values (i))returnDatadefUpdate_col (data):#add columns and fill in whether or not to graduate forDinchData:ifD[5] = ='Grade': D.append ('whether to graduate') elifD[5] = ='Scorpio': D.append ('Graduation') Else: D.append ('not graduated') returnDatadefWt_excel (Excel_name):#writes the processed results to ExcelRB =XLWT. Workbook () RBS=rb.add_sheet ('Sheet1') Data=Delete_messy_code (excel_name) Row=0 forFieldinchUpdate_col (data): forCol, FinchEnumerate (field): Rbs.write (row,col,f) Row+ = 1Rb.save (excel_name) wt_excel (excel_name)
Python read and Write Excel exercises _ remove garbled lines in Excel and add columns