0

I would like to write string text in my outputs excel file; My dataframe output is;

   Cost Centre     Category .. Price
    AQM             R1          10
    BQM             R2          100

Im writing this output to an excel;

 df2.to_excel(writer, sheet_name='Invoice Summary',  index=False)

I would like to add sum value at the end of price column using worksheet write function

 worksheet = writer.sheets['Invoice Summary'']
      text='Total'
        total = sum(df2['Price'] )  
         worksheet.write(1, 0, text)

To do this, i want to know the row, column value of the last cell. How can I find that in python?

Ratha
  • 9,434
  • 17
  • 85
  • 163

1 Answers1

0

Since the worksheet.write function is just using row and column numbers and not Excel addresses, you could simply use df2.shape to get the total number of rows and columns in your dataframe. Since you are excluding the index column, the position at after the end of the price column would be (df2.shape[0] + 2, df2.shape[1] - 1)

Aryan Jain
  • 384
  • 1
  • 7
  • Thanks this is what I wanted. DO you know answer for these 2 questions? https://stackoverflow.com/questions/59383476/how-to-find-total-of-only-one-column-in-python-pandas-pivot-table https://stackoverflow.com/questions/59367985/after-merging-i-miss-pivot-table-columns-in-pandas – Ratha Dec 18 '19 at 01:13