Python collation excel report with Pandas

3

I am generating a report with the Pandas module in Python, I get the data from MySQL, but there is a column with accented data, at the time of generating the report it falls, I leave information related to the problem.

Connection code:

con = MySQLdb.connect(*datosDB)
con.set_character_set('utf8')

Where I upload the data:

multiple_dfs([
    pd.DataFrame({u"Equipos":[]}), title_eq, **#aquí se caee**
    pd.DataFrame({u"Información":[]}),data_eq, 
    pd.DataFrame({"Periodo Seleccionado":[]}),dperiod,
    pd.DataFrame({"Desc":[]}),indic,perc[[" ","dB(A)","db(C)","dB(Z)"]],
    pd.DataFrame({"Segundos":[]}),detalles], "Info", 'tmp/'+equipos+'_'+inicio+'.xls')

Error:

python2.7[11875]: return self.writer.write(data)
python2.7[11875]: File "/usr/lib/python2.7/codecs.py", line 351, in write
python2.7[11875]: data, consumed = self.encode(object, self.errors)
python2.7[11875]: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)
    
asked by Alejandro 11.05.2018 в 14:21
source

1 answer

1

Solution,

It was necessary to add after the

import sys

reload(sys)  
sys.setdefaultencoding('utf8')

With this the problem was solved.

    
answered by 11.05.2018 в 15:34