pandas多班级合并提取教师个人课表,多表同位置填充数据
作者:互联网
import pandas as pd import numpy as np from pprint import pprint pd.set_option('display.max_columns', None) data = [] classList = ["2101大数据", "2101软件", "2102软件"] ddd = pd.DataFrame(np.zeros([200, 25])) ddd.replace(0.0, np.nan, inplace=True) # 循环做数据 def Excute(clas): # data2101 = pd.read_excel("class.xlsx", sheet_name=clas) # 读一个工作簿,切换多个工作表 io = pd.io.excel.ExcelFile("class.xlsx") x1 = pd.ExcelFile("class.xlsx") all_name = x1.sheet_names df = pd.read_excel(io, sheet_name=all_name) # 操作每个sheet页 for sheet in all_name: df_new = df[sheet] print(df_new) tail7 = df_new.tail(7).dropna(axis=1, how="all") for indexs in tail7.index: for i in range(len(tail7.loc[indexs].values)): if (tail7.loc[indexs].values[i] == "奎永杰"): # print(indexs,i) # print(tail7.loc[indexs].values[i]) data.append({"星期": {"value": tail7.loc[indexs][1], "index": [indexs, 1]}, "课程": {"value": tail7.loc[indexs][i - 1] + clas + tail7.loc[indexs][i + 1], "index": [indexs, i]}}) # 替换数据 def changeData(): for i in data: week = i["星期"] ddd.iloc[(week["index"][0]), week["index"][1]] = week["value"] Class = i["课程"] ddd.iloc[(Class["index"][0]), Class["index"][1]] = Class["value"] if __name__ == '__main__': for c in classList: Excute(c) pprint(data) changeData() ddd.to_excel("课表.xlsx")
标签:tail7,sheet,index,loc,pandas,课表,pd,indexs,多表同 来源: https://www.cnblogs.com/zwnsyw/p/15592544.html