python-2.7xlrdxlwtxlutils

Deleting Entire blank row in an existing Excel Sheet using Python


How to remove the entire blank row from the existing Excel Sheet using Python?

I need a solution which DOES NOT : Include reading the whole file and rewriting it without the deleted row.

IS THERE ANY DIRECT SOLUTION?


Solution

  • If using memory is not an issue you can achieve this using an extra dataframe.

    import pandas as pd
    
    #Read from Excel
    xl= pd.ExcelFile("test.xls")
    
    dfs = xl.parse(xl.sheet_names[0])
    df1 = dfs[dfs['Sal'] == 1000]
    df1 = df1[df1['Message']=="abc"]
    
    ph_no = df1['Number']
    
    print df1