0

I have a dataset which has many nan values when I am type the unique values :

plays.yardlineSide.unique()

array(['TB', 'DAL', nan, 'ATL', 'PHI', 'PIT', 'BUF', 'NYJ', 'CAR', 'MIN',
   'CIN', 'DET', 'SF', 'HOU', 'JAX', 'IND', 'SEA', 'TEN', 'ARI',
   'LAC', 'WAS', 'CLE', 'KC', 'MIA', 'NE', 'NO', 'GB', 'NYG', 'DEN',
   'CHI', 'LA', 'LV', 'BAL'], dtype=object)

but the dropna() isn't work instead it perform the rest of values by None like that : ex : plays.yardlineSide output : `0 None 1 None 2 None 3 None 4 None ... 8552 None 8553 None 8554 None 8555 None 8556 None

Fady Esam
  • 31
  • 1
  • 7
  • 2
    Please show how you're using `dropna()` - it's not clear what's being done here. Also see: [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/13843268). – sj95126 Oct 23 '22 at 17:24

1 Answers1

1

I think this might work.

 import pandas as pd

 df = pd.read_csv("file.csv")

 for col in df.columns:
     if df[col].isnull().sum() > 0:
         print("Column {} has {} hidden nan values".format(col, 
 df[col].isnull().sum()))
         df.drop(col, axis=1, inplace=True)

 df.to_csv("file_without_hidden_nan.csv", index=False)
Speezy
  • 50
  • 4