我有一个大的数据框需要修改。对于一个计算,我想将我的数据分组到pborderid上,然后只将具有重复值的行保存到tu wpard中。在
这是我的df的一个例子。在
pborderid pbcarid wsid to_wpadr colli pk_end_time
10 76079450 61838497 hp1 523-369p 1 2016-07-01 00:00:38
11 76079450 61838504 hp1 523-370p 1 2016-07-01 00:00:47
12 76079450 61838110 hp1 523-372p 1 2016-07-01 00:01:05
13 76079450 61838225 hp1 523-372p 2 2016-07-01 00:01:13
14 76079450 61838504 hp1 523-372p 3 2016-07-01 00:01:30
15 76079450 61838497 hp1 523-373p 1 2016-07-01 00:01:45
16 76079450 61838504 hp1 523-377p 1 2016-07-01 00:01:55
17 76079450 61838110 hp1 523-376p 5 2016-07-01 00:02:26
18 76079450 61838225 hp1 523-376p 1 2016-07-01 00:02:33
19 76079450 61838497 hp1 523-376p 6 2016-07-01 00:02:55
使用以下代码可以工作,但是当组数增加时,性能会显著降低,最多需要20秒。我认为只使用pborderid作为组,然后过滤/应用就可以了。在
^{pr2}$有没有人建议我只能使用一个groupcolumn,或者怎样才能提高性能?在
以下是想要的结果:
pborderid pbcarid wsid to_wpadr colli pk_end_time
12 76079450 61838110 hp1 523-372p 1 2016-07-01 00:01:05
13 76079450 61838225 hp1 523-372p 2 2016-07-01 00:01:13
14 76079450 61838504 hp1 523-372p 3 2016-07-01 00:01:30
17 76079450 61838110 hp1 523-376p 5 2016-07-01 00:02:26
18 76079450 61838225 hp1 523-376p 1 2016-07-01 00:02:33
19 76079450 61838497 hp1 523-376p 6 2016-07-01 00:02:55
受^{} 的启发,在本例中我们也可以替换{}操作。实现应该是这样的-
样本运行-
^{pr2}$在我这边的运行时测试似乎没有显示出这种方法比另一个解决方案中列出的
groupby
方法有任何改进。所以,看起来df.groupby
将是首选的方式!在我不知道它是否会更快,但您可以尝试使用^{} 只过滤重复项。在
1米排测向时间:
^{pr2}$相关问题 更多 >
编程相关推荐