Nov-27-2018, 02:34 PM
import pandas as pd df0 = pd.read_csv('test_sample.csv', usecols= ('typeCategory','tran_id', 'issue_d','disbursement_d','fund_id','fund_nm', 'amount','grantee_legal_nm')) df00 = pd.read_csv('test_sample.csv', usecols= ('typeCategory','tran_id', 'issue_d','fund_id','fund_nm', 'amount')) df1 = df0[df0['typeCategory'] == 'grant'] df2 = df00[df00['typeCategory'] == 'gift'] grantingFundID = list(df0['fund_id'].values) #cell_format = workbook.add_format() #df1.columns image_file = open('logo1.png', 'rb') image_data = io.BytesIO(image_file.read()) for fund_id in grantingFundID: df3= df1[df1['fund_id'] == fund_id] df4= df2[df2['fund_id'] == fund_id] writer = pd.ExcelWriter(str(fund_id)+'.xlsx', engine='xlsxwriter') df3.to_excel(writer, 'grants',index=False) df4.to_excel(writer, 'gifts',index=False) workbook = writer.book worksheet = writer.sheets['grants'] worksheet.set_margins(top=1.3) worksheet.set_header('&L&G', { 'image_left': 'logo.png', 'image_data_left': image_data }) worksheet.set_column(0,30,20) worksheet = writer.sheets['gifts'] workbook.close()Here is updated code. I am now adding header to xlsx (logo1.png). I have not added the overview tab. Posting here to save someone else the time in the future.