'How to set borders to the data to the excel with Python pandas/XLSX writer
I am trying to format the excel sheet with the borders with python pandas, but no luck, can anyone please assist.
I have data like this:
I want this in this format:
Solution 1:[1]
It is not straightforward, You have to iterate through the dataframe and add the format to each cell.
cell_format = workbook.add_format()
cell_format.set_border()
for col_num, col in enumerate(df.columns.values):
for row_num, value in enumerate(df[col].values):
worksheet.write(row_num + 1, col_num + 1, value, cell_format)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ze'ev Ben-Tsvi |