从复杂的标准pandas中选择非零最小值

时间:2017-05-12 22:16:36

标签: python pandas

我有以下数据框:

Program    Version  Rand_dist_1   Rand_dist_2  Rand_dist_2    
Autocad     1.0          180        120          126
Autocad     1.1          181        125          123
Autocad     1.2          157        125          125
Autocad     2.0          220        201          173
Autocad     2.1          223        126          100
Autocad     2.3          233        334          233
Autocad     2.5          213        232          321
Autocad     3.2          424        312          312
Autocad     3.5          53         1300         112
sketchup    1.0          22          24          21
sketchup    1.3          23          22          19
sketchup    2.4          65          55          39
sketchup    3.0          32          35          33
sketchup    3.3          43          65          56 

我有随机距离变量来衡量软件版本之间的差异。我猜测的方法并不重要。 我想比较以1.0,1.1,1.2开头的软件的第一个版本与更高版本。我想找到第一个版本和不等于零的更高版本之间的最小距离。 我也可以将Rand_dist_1与Rand_dist_2或Rand_dist_3

进行比较

逻辑可以是这样的:

Compare Autocad 1.0 version with Autocad 2.0, 2.1, 2.3, 2.5, 3.2, 3.5
Compare Autocad 1.1 version with Autocad 2.0, 2.1, 2.3, 2.5, 3.2, 3.5
Compare Autocad 1.1 version with Autocad 2.0, 2.1, 2.3, 2.5, 3.2, 3.5
(Not I am not comparing the first versions with each other)

最终输出应该是这样的:

Program   Min_dist
Autocad      1
sketchup     8

1 个答案:

答案 0 :(得分:1)

您可以在python上使用collections.Counter或groupBy类。