Update particular cell value based on filter and update the cell value using python

Viewed 118

I want to fill attendance timings based on other source(excel). I just want to filter the name and date of the person and i want to update the time hours in excel without creating new sheet and without changing format of the excel values. I am tried using pandas but i creates/writes as new file/sheet. My excel sheet to be updated

import pandas as pd

df1 = pd.read_excel("Msheet.xlsx")
df2 = pd.read_excel("sheet1.xlsx")
print(df1.columns)
for i in range(len(df1)):
    emp_name = df1['Labour Name'][i]
    emp_date = df1['Check In Date'][i]
    man_hours = df1['Man Hours'][i]
    df2_new = df2[df2['Name'] == emp_name]
    df2.loc[df2['Name'] == emp_name, [emp_date]] = man_hours
#df2.to_excel("sheet1.xlsx")
with pd.ExcelWriter("sheet1.xlsx", sheet_name='Sheet1',mode="a") as writer:
    df2.to_excel(writer )

Here i am using two sheets and once is with normal format(no merged cells at all) and another is formatted with merged cells.

This code is creating adding new sheet not updating existing with merged cells format.

0 Answers
Related