'How to export tuple dataframe to excel as a table
Need your support on below question.
From an excel file i need to find total count in each sheet and put that as a summery new summary sheet and finally export that into mail.
For Example: I have an excel file with 5 pages. I followed following steps
- read the excel file from local machine [Export the excel file to python]
- read each sheet and created a dataframe for each sheet
- counted each rows in all the sheet and printed the result
- transferred the print result in to data frame again
Now i want to export this data frame to excel with heading and further to a mail using html. Please see the code below.
sheets = pd.ExcelFile('C:\xxxx\xxxxx\Output\CZ.xlsx')
df1 = pd.read_excel(sheets, 'abc')
df2 = pd.read_excel(sheets, 'abcd')
df3 = pd.read_excel(sheets, 'abcde')
Checking Number of entries in each sheet and printing the result
rows1 = len(df1.axes[0])
print("Page 1: ", rows1)
rows2 = len(df2.axes[0])
print("Page 2: ", rows2)
rows3 = len(df3.axes[0])
print("Page3: ", rows3)
Ans
Page 1: 25 Page2: 35 Page3: 45
############################################################
Putting Print result in to a dataframe
df4=("Page1",rows1)
df5=("Page2",rows2)
df6=("Page3",rows3)
###############################
i need to copy all the above df to one excel sheet like a table like below
Heading Total Count Page1 25 Page2 35 Page 3 45
Solution 1:[1]
Try the following:
df_list = [df1, df2, ... dfn]
df_combined = df_list[0]
for df in df_list[1:]:
df_combined.append(df)
`
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 | YScharf |
