对于使用同一代码的一个Pandas数据帧,我的drop_duplicates()似乎有效,而对于另一个则不起作用。我似乎无法弄清楚。
无法正常工作的情况:
df_select
df_select= #Cont on the next line
df_select.drop_duplicates(subset='RoundDown',keep='first',inplace=False)
df_select
投稿重复的情况:
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
谢谢!
答案 0 :(得分:2)
您可以fillna
并使用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