Python Forum
large csv to many xlsx containing multiple tabs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
large csv to many xlsx containing multiple tabs
#4
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.
Reply


Messages In This Thread
RE: large csv to many xlsx containing multiple tabs - by thatIsTheCase - Nov-27-2018, 02:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extracting sublist from a large multiple molecular file juliocollm 2 3,118 May-25-2020, 12:49 PM
Last Post: juliocollm
  XLSX file with multiple sheets to josn file ovidius 2 3,154 Apr-05-2020, 09:22 AM
Last Post: ovidius
  read multiple .xlsx files and text files in a directory BNB 11 29,626 Jun-07-2017, 07:42 AM
Last Post: BNB
  Write data into existing Excel (xlsx) file with multiple sheets BNB 1 16,107 Jun-01-2017, 04:22 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020