AnalysisNerd
AnalysisNerd

Reputation: 133

Can't seem to drop duplicates on one dataframe but can do it for another

For one Pandas dataframe in the same code, my drop_duplicates() seems to work and for the other it does not work. I can't seem to figure this out.

The situation where it is not working:

df_select
df_select= #Cont on the next line     
df_select.drop_duplicates(subset='RoundDown',keep='first',inplace=False)

df_select

enter image description here

The situation where the drop duplicates works:

df_select1 = pd.DataFrame( {'RoundDown': 
               [0.1,0.2,0.3,0.3],'RoundUp':[0.01,np.nan,0.4,np.nan]})
df_select1

df_select1 = 
df_select1.drop_duplicates(subset='RoundDown',keep='first',inplace=False)
df_select1

enter image description here

Thanks in advance!

Upvotes: 0

Views: 65

Answers (1)

BENY
BENY

Reputation: 323276

You can fillna and using duplicated

df_select1=df_select1[~df_select1.RoundUp.fillna('NaN').duplicated()]
df_select1
Out[212]: 
   RoundDown  RoundUp
0    0.10000  0.01000
1    0.20000      nan
2    0.30000  0.40000

Upvotes: 2

Related Questions