def outer_product(row):
    numerator = df.sum(1).mul(row.sum(0))
denominator = df.sum(0).sum(0)
return numerator.floordiv(denominator)
df.apply(outer_product)
Pandas: outer product of row and col sums