我有一个python文件,该文件使用熊猫从工作簿中读取数据,并对数据执行多项操作,然后将其写回到另一张纸下的同一文件中。在程序的一个循环中,我更新了一个写入excel文件的指针值,该指针值用于更新要在下一次迭代中使用的数据值。但是,当python读取下一组数据值(使用参考公式生成)时,它无法识别这些值在两次迭代之间已更新,并将这些值读取为“ nan”。如何确保python读取实际的更新值而不是“ nan”?
我在此处提供了代码段的副本:
file = 'NS.xlsx'
x1 = pd.ExcelFile(file)
df1 = pd.read_excel(file,sheet_name = 'ReadtoPythonTemplate',skipfooter =
12)
...operations...
book = load_workbook('NS.xlsx')
writer = pd.ExcelWriter('NS.xlsx', engine='openpyxl')
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
print(iteration_index)
iteration_index += 1
update_index = iteration_index + 3 #update pointer in excel file to generate
#new data set in the file to be read in again in the next iteration.
df8 = pd.DataFrame({'Index':[update_index]})
df8.to_excel(writer,"ReadtoPythonTemplate",startrow = 5,startcol = 1,index =
False)
writer.save()
file = []