I want to convert a large dataframe to a series of report tables that replicates the template for each unique id within the dataframe seperated/skipped excel row. I would like to do this with a series of loops. I think I can accomplish through mapping each item in the df to an excel file… but it would take several thousand lines based on the size of the dataframe – any help would be much appreciated!!
import pandas as pd
data = {'id' = [1,2,3]
, 'make' = ['ford','chevrolet','dodge']
, 'model' = ['mustang','comaro','challenger']
, 'year' = ['1969','1970','1971']
, 'color' = ['blue', 'red', 'green']
, 'miles' = ['15000','20000','35000']
, 'seats' = ['leather', 'cloth' , 'leather']
}
df = pd.DataFrame(data)
df.to_excel(r'/desktop/reports/output1.xlsx')
Proposed outcome in excel (one row is skipped between id groupings):
A B C D E F
1 make ford year 1969 miles 15000
2 model mustang color blue seats leather
3
4 make chevrolet year 1970 miles 20000
5 model comaro color red seats cloth
6
7 make dodge year 1971 miles 35000
8 model challenger color green seats leather