2013-08-26 178 views
-1

任何人都知道如何從字典創建一個xls文件? 我充滿文本字的字典,我想把這個DICT在XLS從字典創建一個xls文件

def contar_Repetidas(texto): 
    dic={} 
    l=texto.split() 
    for palabra in l: 
     if palabra not in dic: 
      dic[palabra] = 1 
     else: 
      dic[palabra] +=1 
    return dic 

它diferent becorse,我想從一個字典創建MS Excel中,一個字典

+0

其不重複,只有XLS – Guillermo

回答

2

使用xlwt模塊:

import xlwt 

dic = contar_Repetidas("Some Text Here") 

wb = xlwt.Workbook() 
ws = wb.add_sheet("Your Sheet") 

count = 0 
for word, num in dic.items(): 
    count += 1 
    ws.write(count, 1, word) 
    ws.write(count, 2, num) 

wb.save("/Path/To/Save/Example.xls")