If you are already using pandas for your task, you can use it easily to create a dataframe and turn it into an Excel sheet. If not, it is easier to use xlsxwriter rather than pandas because pandas is a little heavy library.
pip install XlsxWriter
import xlsxwriter
workbook = xlsxwriter.Workbook("MyExcel.xlsx")
worksheet = workbook.add_worksheet()
There are multiple ways to write the data to excel. You can use write_row(), write_column() or write cell by cell also.
write_row(row, column, data)
row = [1, 2, 3, 4, 5]
worksheet.write_row(1, 2, row)
write_column(row, column, data)
column= [1, 2, 3, 4, 5]
worksheet.write_column(1, 2, column)
write(row, column, data)
worksheet.write(0, 1, "Hello")
worksheet.write(0, 2, "World")
Finally, close the workbook.
workbook.close()
Like this, there are many ways to write data and also you can conditional formatting to your cells or rows or columns. The documentation can be found here.