1

There is one CSV file with many rows and columns of data that needs to be copied into sheet1 starting at row 11 of a "master" Excel .xlsx file.

There are graphs and formatting in the "master" excel file that need to be preserved. The problem that I'm having is that the "master" Excel file, python_out.xlsx, is overwritten with my code and the graphs and formatting are wiped out.

I've found a couple of helps like Write values to a particular cell in a sheet in pandas in python but they are only writing a few cells worth of data and not copying over an entire .csv file.

import os
import pandas as pd
from openpyxl import load_workbook
    
    
read_file = pd.read_csv(r'C:\4336Gen5 size\Noise\mode0\mode_0_40c_noise.csv')
    
read_file.to_excel(r'C:\4336Gen5 size\Noise\mode0\python_out.xlsx', startcol=0, startrow = 10, index = None, header = True)
Alan
  • 2,914
  • 2
  • 14
  • 26
Matt
  • 11
  • 1
  • 1
    It may not be possible to append data to an existing sheet using Pandas. The underlying OpenPyxl library can do it, just not Pandas. You can add the dataframe to a new sheet within the existing workbook (although again this is using feature of the underlying openpyxl library called "ExcelWriter") – Alan Jan 31 '22 at 16:50

0 Answers0