HeelMega
HeelMega

Reputation: 508

Update entire excel row in panda

I am trying to parse an excel file and change the data currently in the excel file. The issue i m running into is that it is replacing it vertically. I need it to replace it horizontally starting from the given row and column

import pandas as pd
from openpyxl import load_workbook

fn = 'test.xlsx'

df = pd.read_excel(fn, header=None)
df2 = pd.DataFrame({'Data': [13, 24, 35, 46]})

writer = pd.ExcelWriter(fn, engine='openpyxl')
book = load_workbook(fn)
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)

df.to_excel(writer, sheet_name='Sheet1', header=None, index=False)
df2.to_excel(writer, sheet_name='Sheet1', header=None, index=False,
             startcol=10,startrow=6)

writer.save()

Upvotes: 1

Views: 791

Answers (1)

xyzjayne
xyzjayne

Reputation: 1387

You need to create a row not a column.

df2 = pd.DataFrame.from_dict({'Data': [13, 24, 35, 46]},orient = 'index')

Upvotes: 2

Related Questions