python - 尝试附加到 Excel 工作表时,我不断收到意外的数据类型错误
问题描述
在我的代码中,我创建了一个新的 excel 表,并希望将我的 python 字典中的数据添加到我的 excel 单元格中。但是,我不断收到意外的数据类型错误。
#this creates a new workbook call difference
file = xlrd.open_workbook('/Users/vhim/Documents/Exception_Cases/Orders.xls')
wb = xl_copy(file)
Sheet1 = wb.add_sheet('differences')
#this creates header for two columns
Sheet1.write(0,0,"SO_Numbers")
Sheet1.write(0,1,"Booking Values")
#this would store all the of Key, value pair of my dictionary into their respective SO_Numbers, Booking Values column
#I want SO_Numbers column to add the Key data and Booking Values columns to add the value data
print(len(diff_so_keyval))
rowplacement = 1
while rowplacement < len(diff_so_keyval):
for k, v in diff_so_keyval.items():
Sheet1.write(rowplacement,0,k)
Sheet1.write(rowplacement,1,v)
rowplacement = rowplacement + 1
This is what I have in my diff_so_keyval dictionary
diff_so_keyval = {104370541 [31203.7]
106813775 [187500.0]
106842625 [60349.8]
106843037 [492410.5]
106918995 [7501.25]
106919025 [427090.0]
106925184 [30676.4]
106941476 [203.58]
106941482 [203.58]
106941514 [407.16]
106962317 [61396.36]}
4 for k, v in diff_so_keyval.items():
5 Sheet1.write(rowplacement,0,k)
----> 6 Sheet1.write(rowplacement,1,v)
7 rowplacement = rowplacement + 1
Exception: Unexpected data type <class 'float'>
解决方案
推荐阅读
- node.js - 如何将 Promise.all 与 fs.unlink 回调一起使用?
- python - 使用python在Android手机上下载图片
- highcharts - 如何在 highcharts 中导出带有自定义 html 部分的图表?
- google-tag-manager - 多行的dataLayer是可能的吗?
- php - PHP while循环在发送后中断
- python - Python触发/模拟自定义浏览器协议
- r - 从 excel 电子表格在 R 中制作出版质量表
- javascript - 如何使用 JavaScript 获取设备的最准确 GPS 坐标?
- android - apollo-android 对 express-graphql 的请求总是导致 http 400
- r - 完成下一个专栏系列