0

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.

  • I think you should check this [Link](https://stackoverflow.com/questions/10857924/remove-nan-null-columns-in-a-pandas-dataframe) out – anosha_rehan Mar 28 '22 at 06:59
  • This link is helpful, but my dataframe columns donot have NaN values. They are empty. – noorulsaba islam Mar 28 '22 at 07:02
  • can you provide a sample of your dataframe – Ali Sultan Mar 28 '22 at 07:04
  • The links mentioned above also have solutions for `null` values, have you tried those solutions or something similar? – anosha_rehan Mar 28 '22 at 07:06
  • Yes, I have tried but for these links, NA values should be present, then it can remove. – noorulsaba islam Mar 28 '22 at 07:14
  • There is no such thing as "*empty*" cells, you need to provide a sample for explicitness. What is the output of `df.head().to_dict()` ([edit](https://stackoverflow.com/posts/71643477/edit) your question)? The only case where columns can be empty is if there are no rows. In which case removing empty columns would be removing the whole dataframe. – mozway Mar 28 '22 at 07:25

1 Answers1

1

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)
DOBBYLABS
  • 65
  • 4