Python实训day09pm【Python处理Excel实际应用】
- Python實訓-15天-博客匯總表
目錄
1、實訓分組
2、練習題
2.1、課堂練習1
2.2、課堂練習2
1、實訓分組
4人一組,完成實訓大作業(yè)和實訓報告。
每組只提交一份大作業(yè) 和 一份實訓報告。附上一個說明文檔:組長來說明每個人的工作量。
①咱們兩個班參與本次實訓的同學共計72名同學,分為18個組;
②每組為4名同學;
③每組第1名同學為組長,其余3名同學為組員;
④大家自行結合進行分組,分組名單于今天晚上8點前完成,后續(xù)實訓報告等事宜由小組形式進行,每組提交一份即可。
大家互相轉(zhuǎn)告,辛苦@所有人。
爬蟲、圖片、DataFrame等結合應用的大作業(yè),最終成績:日常考勤+(日常作業(yè))+大作業(yè),周末班主任找到大家核對本周考勤。
2、練習題
2.1、課堂練習1
下午的題目任務:
真實生活應用場景:有兩個excel表格,
總錄取名單.xlsx,表1:總的學生錄取信息(考號、學號、姓名、性別、專業(yè)等);
我的名單.xls,表2:我的學生名單(姓名、性別、身份證號、考號、學院等信息),唯獨沒有學號信息
要求:
1.根據(jù)考號的對照,將總名單中的學號,加入到我的名單中。
2.可能會有個別同學沒有被錄取,總錄取名單中找不到該生的考號,將這些人找出來,并將學號設置為0。
左上角 File ---> Settings ---> project ---> +號搜索安裝openpyxl。openpyxl
import pandas as pd import xlrd import xlwt# 讀取 total = pd.read_excel(r'C:\Users\lwx\Desktop\總名單.xlsx'); sub = pd.read_excel(r'C:\Users\lwx\Desktop\我的學生名單.xls');# 根據(jù)sub中的“準考證號”,到total中與“考生號”比較,找到對應行的“學號”sub_zkz = list(sub['準考證號']); print(len(sub_zkz)) # 625 total_ksh = list(total['考生號']); print(len(total_ksh)) # 8635xhs = []; # 逐個查找每個準考證號,在total中的第幾行(索引) for zkz in sub_zkz:if int(zkz) in total_ksh:index = total_ksh.index(int(zkz)); # 行下標(索引)xh = total.loc[index, '學號']; # 找到學號xhs.append(xh);else:xhs.append(0);print(xhs)sub['學號'] = xhs;# 導出 sub.to_excel(r'C:\Users\lwx\Desktop\處理后.xls', index=False); # index=False,不要行索引 print("Over")F:\Python38\python.exe F:/JetBrains/2pythonSpace/pythonCode/實訓lwx作業(yè)/day09-pm-01.py 625 8635 F:/JetBrains/2pythonSpace/pythonCode/實訓lwx作業(yè)/day09-pm-01.py:30: FutureWarning: As the xlwt package is no longer maintained, the xlwt engine will be removed in a future version of pandas. This is the only engine in pandas that supports writing in the xls format. Install openpyxl and write to an xlsx file instead. You can set the option io.excel.xls.writer to 'xlwt' to silence this warning. While this option is deprecated and will also raise a warning, it can be globally set and the warning suppressed.sub.to_excel(r'C:\Users\lwx\Desktop\處理后.xls', index=False); # index=False,不要行索引 OverProcess finished with exit code 02.2、課堂練習2
將表1中的分析樣的行數(shù)據(jù),拷貝到表2中對應的“那些”行里:
例如:
dw001 ---> dw001A dw001B
dw002 ---> dw002A dw002B dw002C dw002D
吾日三省吾身。——《論語·學而》
?
總結
以上是生活随笔為你收集整理的Python实训day09pm【Python处理Excel实际应用】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python实训day09am【Pand
- 下一篇: 电脑常用工具(阅读代码、文件搜索、思维导