根据另一列的条件删除一列中重复的行 [英] Deleting rows that are duplicated in one column based on the conditions of another column
本文介绍了根据另一列的条件删除一列中重复的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的数据集的一个例子;
Here is an example of my data set;
Date Time(GMT)Depth Temp Salinity Density Phosphate
24/06/2002 1000 1 33.855 0.01
24/06/2002 1000 45 33.827 0.01
01/07/2002 1000 10 13.26 33.104 24.873 0.06
01/07/2002 1000 30 12.01 33.787 25.646 0.13
08/07/2002 1000 5 13.34 33.609 25.248 0.01
08/07/2002 1000 40 12.01 34.258 26.011 1.33
15/07/2002 1000 30 12.04 34.507 26.199 0.01
22/07/2002 1000 5 13.93 33.792 25.269 0.01
22/07/2002 1000 30 11.9 34.438 26.172 0.08
29/07/2002 1000 5 13.23 34.09 25.642 0.01
我想删除重复的行,以便每个日期只有一行,我想根据深度执行此操作,我想保留最大(最深)深度的行.有任何想法吗?
I want to delete duplicate rows so that I only have one row per date, I want to do this based on the Depth, I would like to keep the row with the greatest (deepest) depth. Any ideas?
推荐答案
假设你在 df 中有数据
Lets say you have data in df
df = df[order(df[,'Date'],-df[,'Depth']),]
df = df[!duplicated(df$Date),]
这篇关于根据另一列的条件删除一列中重复的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文