2016-05-12 10 views
0

Excel(xlsx)ファイルをcsvに変換します。私はそうするように、この関数をコード化されたが、quotechart = '"' 動作していないしているPython-xlrdとunicodecsv

import xlrd 
import unicodecsv 

def xls_to_csv (xls_filename, csv_filename): 

    wo = xlrd.open_workbook(xls_filename) 
    st = wo.sheet_by_index(0) 

    fl = open(csv_filename,"wb") 
    csv_out = unicodecsv.writer(fl, encoding='utf-8', quotechart='"') 

    for row_number in range (st.nrows): 
     csv_out.writerow(st.row_values(row_number)) 

    fl.close() 
xls_to_csv('PT_BR.POSTP.20160508_vx27.xlsx','prueba.csv') 

電流出力を:。

Category,Term,POS,Term,POS,Term,POS,,,, 
A001,atendimento,sust,concessionário,sust,não,adv,bom,adj,, 
... 

所望の出力:

"Category","Term","POS","Term","POS","Term","POS" 
"A001","atendimento","sust","concessionário","sust","não","adv","bom","adj" 
... 

答えて

0

この中に追加してみてくださいcsvファイルライターオブジェクトの代わりにquotechart='"'

quoting = unicodecsv.QUOTE_ALL 

も試していません。

関連する問題