Search code examples
pythonexcelpandasrowlines

Delete row from a file with blank fields using Python


I need to delete rows from an Excel file with Python.

I need to check three columns and if they are empty then delete that row.

I tried:

NewDf = empresa.ix[[empresa['name']==" "] and [empresa['cpf']==" "]]

Solution

  • You can use dropna for that. The subset param specify the columns you whant to check. 'All' mean, you whant to delete row all 3 columns are empty. You can set how to 'Any' to delete rows if only one columns is empty.

    df.dropna(axis=0, how='all', , subset=["col1", "col2", "col3"], inplace=True)