http://en.wikipedia.org/wiki/Cartesian_product
import pandas as pd
df = pd.DataFrame(zip(['A','B','C','D','E','A','B','C','A'],[1,2,3,4,5,2,3,5,5]),columns=['rep_id','val'])
df = df.sort('val')
cartesian_product = pd.merge(df, df,on='val')
cartesian_product = cartesian_product[cartesian_product['rep_id_x'] != cartesian_product['rep_id_y']]
cartesian_product[['val','rep_id_x','rep_id_y']]
DF:
rep_id val
0 A 1
1 B 2
5 A 2
2 C 3
6 B 3
3 D 4
4 E 5
7 C 5
8 A 5
cartesian_product:
val rep_id_x rep_id_y
2 2 B A
3 2 A B
6 3 C B
7 3 B C
11 5 E C
12 5 E A
13 5 C E
15 5 C A
16 5 A E
17 5 A C
*「我想計算所有可能的對 'rep_id',然後找到那些值共同的rep_ids。「* ....所有可能的對之間你的意思? – miradulo
是對之間 – matnewguy
你有樣品數據和嘗試代碼? – miradulo