【发布时间】:2019-07-09 07:24:07
【问题描述】:
我想比较两个series中的元素。
0 1
1 3
2 4
3 2
4 4
Name: s1, dtype: int32
0 3
1 3
2 0
3 5
4 1
Name: s2, dtype: int64
为了方便比较series,我使用了itertools.combinations:
x = combinations(s1, 2)
y = combinations(s2, 2)
结果x:
(1, 3)
(1, 4)
(1, 2)
(1, 4)
(3, 4)
(3, 2)
(3, 4)
(4, 2)
(4, 4)
(2, 4)
是:
(3, 3)
(3, 0)
(3, 5)
(3, 1)
(3, 0)
(3, 5)
(3, 1)
(0, 5)
(0, 1)
(5, 1)
比较的方法部分类似于 Kendall 的 tau 距离。 x (x1, x2) 中的对,以及 y (y1, y2) 中的对。如果x1 > x2和y1 > y2,或者x1 < x2和y1 < y2,那么score = score+1;否则,score = score。但到目前为止,我仍然无法比较对中的元素。
我收到m1、m2 和m1|m2:
m1 :
0 False
1 False
2 False
3 False
4 False
5 False
6 False
7 False
8 False
9 False
dtype: bool
平方米:
0 False
1 False
2 True
3 False
4 False
5 False
6 False
7 False
8 False
9 False
dtype: bool
m1|m2:
0 False
1 False
2 True
3 False
4 False
5 False
6 False
7 False
8 False
9 False
dtype: bool
我得到了和你一样的结果。我不知道为什么它加起来这么多时间。
m1 和 m2 都包含默认的所有错误值。确实如此,而且目前的结果在理想情况下是正确的。但我希望score 每次(m1 | m2) == true 加 1。
score
0
0
1
0
0
0
0
0
0
0
上述分数的理想结果。
【问题讨论】:
标签: python python-3.x pandas jupyter-notebook