Q:

find couple of objects from a dataframe

How can I avoid the two for loops and optimize my code to be able to handle big data?
import pandas as pd 
import numpy as np
array = np.array([[1,'aaa','bbb'],[2,'ccc','bbb'],[3,'zzzz','bbb'],[4,'eee','zzzz'],[5,'ccc','bbb'],[6,'zzzz','bbb'],[7,'aaa','bbb']])
df= pd.DataFrame(array)
l=[]
for i in range(len(df)):
    for j in range(i+1,len(df)):
        if (df.loc[i][1] == df.loc[j][1]) & (df.loc[i][2] == df.loc[j][2]):
            l.append((df.loc[i][0],df.loc[j][0]))

A:

Group by the second and third column. Then use the combination function: chain and combinations. 
from itertools import combinations
list(chain(*df.groupby(by=[1, 2])[0].apply(lambda x: combinations(x, 2))))
[('1', '7'), ('2', '5'), ('3', '6')]

Change the dataset a bit.
array = np.array([[1,'aaa','bbb'],[2,'ccc','bbb'],[3,'zzzz','bbb'],
                  [4,'eee','zzzz'],[5,'ccc','bbb'],[6,'zzzz','bbb'],
                  [7,'aaa','bbb'], [8, "aaa", "bbb"], [9, 'zzzz','bbb']])
df = pd.DataFrame(array)

list(chain(*df.groupby(by=[1, 2])[0].apply(lambda x: combinations(x, 2))))

[('1', '7'),
 ('1', '8'),
 ('7', '8'),
 ('2', '5'),
 ('3', '6'),
 ('3', '9'),
 ('6', '9')]

list(chain(*df.groupby(by=[1, 2])[0].apply(lambda x: combinations(x, 2))))
1.67 ms ± 34.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

