Pasting Dataframe in seperate excel files keeping all existing data in python

Viewed 45

I have 10 excel files with one sheet in each excel file:- Sheet Name= Report Output 1

I have created dataframe based on 10 excel files by importing all 10 files through glob and pandas.

import glob
import pandas as pd

df = pd.DataFrame()
for f in glob.glob(filename*.xlsx):
    info = pd.read_excel(f, sheetname='Report Output 1')
    df = df.append(info)

Did some filtration, merging and calculations as per the requirement. Now I have one consolidated dataframefinal_df which has data for 10 files after my calculations.

I want to paste the dataframe final_df back to all respective 10 files in New Sheet by splitting or groupby with unique value (column name Source in each file which has unique value) keeping original data in existing files(Sheet Name - Report Output 1) as it is.

I know openpyxl can perform this function through Python OpenPyXl dataframe_to_rows but how to write the code which will copy the dataframe to separate sheets.

0 Answers
Related