I have a Python script which uses some embedded SQL to create a series of dataframes. Each dataframe holds a list of ID numbers, like this:
ID_number
---------
123
456
789
What I want to do is create a csv or xlsx file in which the results of each dataframe are held in their own tab, along with a brief header string in cell A1. So for example, the first tab would look like this:
The results from dataframe one are:
123
456
789
I know I can write the results of a dataframe to a csv or xlsx file using the to_csv or to_excel functions, a bit like this:
df.to_csv("my_file.csv", mode ='x', index = False)
However, I'm not sure how to write multiple dataframes to different tabs within the same file, or add the header string.
Does anyone know how to do this please?