jahmed31
jahmed31

Reputation: 3786

openpyxl delete rows and update the excel file

I just simply want to delete some rows from the excel sheet and update the file, But seems like there is no way to update the file. If so please tell

Secondly if i try to delete the rows/columns and and try to iterate over the rows again then again those rows or columns being showing in the data.

for row in (0, 1, 2, 3):
    wb.delete_rows(row)

for c in (0, 1, 3):
    wb.delete_cols(c)

Any help would be much appreciated.

Upvotes: 1

Views: 279

Answers (1)

fakhir hanif
fakhir hanif

Reputation: 655

I would suggest using the pandas library for this.

You will have other features as well like merging cells, groupings. This would help you more with extensive features with your data set.

import pandas as pd

df = pd.read_excel("excelfile.xls")

pd.drop(['col1', 'col2'])

for more detail please visit below link https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html

Upvotes: 1

Related Questions