def wards_method(df, cluster1, cluster2):
    """
    Computes the distance of two clusters by ward's method
    

    Parameters
    ----------
    
    df (pd.DataFrame)
        Data points
    cluster1, cluster 2 (pd.Index)
        The elements of two clusters

    Returns
    -------
    The change of the sum of squared erros after clusters merge
    """

    mean_vec1 = df.loc[cluster1].mean()
    mean_vec2 = df.loc[cluster2].mean()
    n1, n2 = len(cluster1), len(cluster2)
    w = (n1 * n2 / (n1 + n2))

    return  w * ((mean_vec1.values - mean_vec2.values) ** 2).sum()