In python removing rows from a excel file using xlrd, xlwt, and xlutils

后端 未结 3 895
情话喂你
情话喂你 2021-01-14 16:51

Hello everyone and thank you in advance.

I have a python script where I am opening a template excel file, adding data (while preserving the style) and saving again.

3条回答
  •  灰色年华
    2021-01-14 17:19

    I achieved 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)
    

提交回复
热议问题