用不同的数据写两个数据框到一个excel文件。 pandas

这可能是一个奇怪的问题,但我试图写一些数据到Excel工作表,以便从另一个工作表中读入数据。 我现在已经build立了,所以我可以写一个DataFrame并根据这些信息改变单元格的颜色。 现在我想在保持颜色的同时在这些单元格中添加新的信息。

import pandas as pd, datetime as dt import glob, os import math runDir = "/Users/AaronsMac/Documents/" if os.getcwd() != runDir: os.chdir(runDir) files = glob.glob("edcLineup_*.xlsx") schedule = glob.glob("edcSetTime*.xlsx") print schedule for each in files: sheets = pd.ExcelFile(each).sheet_names sheets = sorted(sheets) df = {} for sheet in sheets: df = pd.read_excel(each, sheet, index_col='Artists') #print df colNames = list(df.columns.values) artists = list(df.index.values) # print colNames # print artists for name in colNames: schedule_sheets = pd.ExcelFile(schedule[0]).sheet_names scheduleData = {} for s_sheet in schedule_sheets: scheduleData[s_sheet] = pd.read_excel(schedule[0],s_sheet, index_col='Time') finalSched = pd.concat(scheduleData).unstack(0) stages = list(finalSched.columns.values) indSched = finalSched.copy() asciiName = name.encode('ascii','ignore') for stage in stages: for dj in artists: for time,prevtime in zip(list(finalSched.index.values),list(finalSched.index.values)[1:]): if type(indSched.at[time,stage]) == float: if math.isnan(indSched.at[time,stage]): indSched.at[time,stage] = indSched.at[prevtime,stage] finalSched.at[time,stage] = finalSched.at[prevtime,stage] if type(indSched.at[time,stage]) == str or type(indSched.at[time,stage]) == unicode: if indSched.at[time,stage].lower() == dj.lower(): indSched.at[time,stage] = df.at[dj,name] writer = pd.ExcelWriter(asciiName+'_schedule.xlsx',engine='xlsxwriter') indSched.to_excel(writer,sheet_name=s_sheet) workbook = writer.book worksheet = writer.sheets[s_sheet] worksheet.conditional_format('B3:Y48',{'type': '3_color_scale'}) writer.save()` 

以上是我目前的代码(我相信这是相当低效的,但我只是试图让事情工作)。 我已经尝试做以下覆盖数据,但它给了我一个Excel错误,说我需要修复文件之前,我可以看看它。 它也消除了着色。

 indSched.to_excel(writer,sheet_name=s_sheet) workbook = writer.book worksheet = writer.sheets[s_sheet] worksheet.conditional_format('B3:Y48',{'type': '3_color_scale'}) finalSched.to_excel(writer,sheet_name=s_sheet) writer.save() 

我有点难过,也许这是完全错误的方式去做的事情,但只是想知道如果有人有一些build议。

这里是我用来从中提取数据的两个文件。 一 , 二