Я получаю неожиданную ошибку типа данных при попытке добавить в лист Excel - PullRequest
0 голосов
/ 18 октября 2019

В своем коде я создал новый лист 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'>
...