Python Forum
Dataframe to template - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Dataframe to template (/thread-28023.html)



Dataframe to template - Kristenl2784 - Jul-01-2020

Hello,

How would I go about copying a dataframe to an excel template without overwriting data in the template? The template has 10 tabs with data in it. I want to copy the dataframe and paste it into template tab 'data1' column B, row 15.

import pandas as pd
import openpyxl as xl


df1 = pd.read_excel('C:\\work\\All_Data.xlsx', sheet_name = 'Report1', nrows=9, header=None)

df2 = pd.read_excel('C:\\work\\All_Data.xlsx', sheet_name = 'Report1', skiprows=9, header=None)



df2 = df2[df2["Direction"].str.contains("Down*", na=False)]


df2 = df2[(df2['Time Step']  >= '0.09:00:00') & (df2['Time Step'] <= '0.09:01:39')]

template = xl.load_workbook('C:\\work\\Template.xlsx')
template_sheet_name = template['data1']