Автоподгонка длины столбца в xlsxwriter - PullRequest
0 голосов
/ 31 августа 2018

Я пытаюсь использовать код ниже, чтобы найти максимальную длину столбцов и соответственно отрегулировать их ширину, но получаю сообщение об ошибке:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xae'
in position 8: ordinal not in range(128)

Ниже мой код:

# Iterate through each column and set the width == the max
# length in that column A padding length of 2 is also added
for i, col in enumerate(df1.columns): 
    # Find length of column i    
    column_len = df1[col].astype(str).str.len().max()
    # Setting the length if the column header is larger than the
    # max column value length
    column_len = max(column_len, len(col)) + 2
    # Set the column length        
    worksheet.set_column(i, i, column_len)
...