答案 0 :(得分:2)
您可以使用以下格式将格式添加到列中(必须使用样式来获得所需的厚度):
import pandas as pd
import numpy as np
import xlsxwriter
df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c'])
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
workbook = writer.book
worksheet = writer.sheets['Sheet1']
border_fmt = workbook.add_format({'bottom':5, 'top':5, 'left':5, 'right':5})
worksheet.conditional_format(xlsxwriter.utility.xl_range(0, 0, len(df), len(df.columns)), {'type': 'no_errors', 'format': border_fmt})
writer.save()