Home > Net >  Remove the empty columns in pandas data frame
Remove the empty columns in pandas data frame

Time:03-29

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.

CodePudding user response:

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)
  • Related