0

Dears,

How to remove row from excel using Python/PySimpleGUI. Knowing that I'm using the reverse process of adding rows to excel file using PySimple :

Add Row :

import PySimpleGUI as sg import pandas as pd .......... [sg.Button('Submit', size=(6, 1), button_color=('White','Dark'))] if event == 'Submit': new_record = pd.DataFrame(values, index=[0]) df = pd.concat([df, new_record], ignore_index=True) df.to_excel(EXCEL_FILE, index=False) sg.popup('Data Saved!', font=("Helvetica", 11),text_color='Yellow', no_titlebar=True, button_type=5) clear_input() 

And for deleting row with a given key , i'm using the following code and didn't help :

 if event == 'Delete': df = pd.read_excel(EXCEL_FILE) df = df[df.Column1!= 'ENTRY'] df.to_excel(EXCEL_FILE, index=False) sg.popup('Entry Deleted!') 

Could you please advice ? Thanks

1 Answer 1

1

Could you drop the column from the df and then rewrite to excel if needed?

df = df.drop(['rowToDelete'])

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @Virt, I add your recommendation, unfortunately didn't help, I got the following error : df = df.drop[df.Column1!='ENTRY'] ~~~~~~~^^^^^^^^^^^^^^^^^^ TypeError: 'method' object is not subscriptable
Hi again, just to clarify little bit more, I'm using the following topic : youtube.com/watch?v=svcv8uub0D0 , to create an excel form using python, and since the program is creating duplicate enteries with same value in 1st column and not checking what is inside, so I want to find a way to check if this entery is already exists, than I will delete it ( in case I want to change data inside ) or use another method for updating same entery instead of creating a duplicate one. Hope you got my point . Thx
@Jason Yang, Could you please help on this topic? Thanks in advance
Anyone can help on this topic?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.