如何使用Python/PySimpleGUI从Excel中删除行

q3aa0525  于 2022-11-18  发布在  Python
关注(0)|答案(1)|浏览(136)

亲爱的,
如何使用Python/PySimpleGUI从Excel中删除行。知道我正在使用PySimple向Excel文件添加行的相反过程:
新增列:

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()

对于删除具有给定键的行,我使用以下代码,但没有帮助:

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!')

你能给我点建议吗?谢谢

kgsdhlau

kgsdhlau1#

您是否可以从df中删除该列,然后在需要时重写为excel?
df = df.drop(['rowToDelete'])

相关问题