Search code examples
pythonpandasdataframedata-cleaning

Remove the empty columns in pandas data frame


how to remove empty columns in pandas data frame. However, these empty columns does not have any NaN values. I have the this type of output after running the dataframe. I want to remove these empty columns which are attached in image. In my dataframe there is no NaN or NA values only empty entries.


Solution

  • first of all i would like to recommend you to replace the ' ' values by 'NaN'

    df['Name'].replace('', np.nan, inplace=True)
    

    After that u can use basic function drop

    df.dropna(subset=['Name'], inplace=True)