[英]Make new dataframe from existing dataframe by removing duplicates from columns
I have a dataframe 'merged_df' that looks like this:我有一个如下所示的数据框“merged_df” :
I am interested in the columns, 'login_id' & 'volume' , but there are many duplicate entries in the 'login_id' column.我对'login_id'和'volume'列感兴趣,但在 'login_id' 列中有许多重复的条目。 I want to make another dataframe with unique 'login_id' and the sum of 'volume' for each unique 'login_id'.
我想制作另一个具有唯一“login_id”的数据框和每个唯一“login_id”的“volume”总和。
Will this get you what you want?这会让你得到你想要的吗?
df = pd.DataFrame({
'login_id' : [1, 1, 2, 2, 3],
'Volumn' : [10, 10, 20, 20, 50]
})
df_new = df.groupby('login_id', as_index = False)['Volumn'].sum().sort_values('Volumn', ascending = False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.