我有一个像下面这样的大熊猫
在下面的df中,在索引0,1
&
2,3
……& 500,501,502
中发现了X&Y列中的重复值,第二轮开始时,索引1000, 1001 & 1002,1003 & ....1200,1201....
it goes on
中X&Y列中的重复值相同,但权重列中的权重不同。你知道吗
index x y weight
0 59.644 10.72 0.69
1 59.644 10.72 0.82
2 57.822 10.13 0.75
3 57.822 10.13 0.68
4 57.822 10.13 0.20
.
.
500 53.252 10.85 0.15
501 53.252 10.85 0.95
502 53.252 10.85 0.69
.
.
1000 59.644 10.72 0.85
1001 59.644 10.72 0.73
1002 57.822 10.13 0.92
1003 57.822 10.13 0.15
.
.
.
1200 53.252 10.85 0.78
1201 53.252 10.85 1.098
我的要求
I would like to have my df
1) Avoid repeated/duplicate row values in X & Y which has weight value less than 0.602) But still duplicates in X & Y column repeats, So now i want to compare the weight values between duplicate rows & remove the rows which has lesser weight.
3) If I use the below code, it removes all the duplicates between x & y
df_2.groupby(['X', 'Y'], as_index=False,sort=False)['weight'].max()
But I want to compare the first occured duplicates and remove them, then the 2nd, then 3rd and so on ..so that the continuity of duplicate value prevails after some rows. for better understanding, please refer the below required df
df应该是什么样子的:
index x y weight
1 59.644 10.72 0.82
2 57.822 10.13 0.75
.
.
501 53.252 10.85 0.95
.
.
1000 59.644 10.72 0.85
.
1002 57.822 10.13 0.92
.
.
1201 53.252 10.85 1.098
.
.
我尝试过使用if语句,但是代码行增加了。 我认为应该有一个替代的Python方式,使它更容易。(内置函数或使用numpy) 任何帮助都将不胜感激。你知道吗
与注释中提到的@Erfan一样,这里有必要通过helper
Series
对连续组进行分组:相关问题 更多 >
编程相关推荐