Reputation: 133
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
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
Thanks in advance!
Upvotes: 0
Views: 65
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