Python to delete a row in excel spreadsheet

前端 未结 6 719
走了就别回头了
走了就别回头了 2021-01-20 03:21

I have a really large excel file and i need to delete about 20,000 rows, contingent on meeting a simple condition and excel won\'t let me delete such a complex range when us

6条回答
  •  死守一世寂寞
    2021-01-20 03:50

    I have achieved this using Pandas package....

    import pandas as pd
    
    #Read from Excel
    xl= pd.ExcelFile("test.xls")
    
    #Parsing Excel Sheet to DataFrame
    dfs = xl.parse(xl.sheet_names[0])
    
    #Update DataFrame as per requirement
    #(Here Removing the row from DataFrame having blank value in "Name" column)
    
    dfs = dfs[dfs['Name'] != '']
    
    #Updating the excel sheet with the updated DataFrame
    
    dfs.to_excel("test.xls",sheet_name='Sheet1',index=False)
    

提交回复
热议问题