Issue
I want to ask you how to add dataframe as new list in existing excel file. For example, I have flat.xlsx file with 2 lists: sheet1 and sheet2. I want to add new list named Data into this file.
Can you please help me?
Solution
Calling df.to_excel(filename)
with a target filename will overwrite an existing file. You must use an ExcelWriter and pass this as the first argument to df.to_excel().
Try this:
import pandas as pd
with pd.ExcelWriter('test.xlsx', engine='openpyxl', mode='a') as writer:
df = pd.read_csv('test.csv') # open/create dataFrame to add
df.to_excel(writer, sheet_name='new_sheet3')
Answered By - CodeMonkey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.