Just a Python tip:

    [unique_cols.append(col) for col in matched_cols if col not in unique_cols]

this can be written as

    unique_cols = list(set(matched_cols))

That is, convert the list into a set and back to a list. Since you're just calling `len()` on these lists anyways you can just use the set itself:

    unique_cols = set(matched_cols)
    unique_rows = set(matched_rows)
    return min(len(unique_cols), len(unique_rows))