python - python读取excel文件不正确
问题描述
我有一个 python 文件,它使用 pandas 从工作簿中读取数据并对数据执行多项操作并将其写回到单独的工作表下的同一个文件中。在程序中的一个循环中,我更新了一个写入 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 = []
解决方案
推荐阅读
- eclipse - 使用 Aether Eclipse 检索工件发布日期
- c - 在 FAT32 上自己创建文件后无法删除文件
- xml - 是否可以允许任何有效的 XML 作为 XSD 中元素的子元素?
- php - 使用 PHP 获取 Wordpress 网站类别列表的正确方法是什么?
- javascript - 何时使用 L.TileLayer 与 L.tileLayer
- python - 将变量名作为命令行参数传递给打印
- c - 为什么此代码打印 0?
- css - Bootstrap:主体上的模态和变换比例
- java - YouTubePlayerView 画中画安卓
- python - 不可能训练神经网络计算异或