def correlation_matrix(data):
    """Calculates the correlation matrix of a dataframe and orders by
    degree of correlation.

    Args:
        data (pandas dataframe): The data object.

    Returns:
        pandas series: The correlation matrix sorted with highest\
        correlation on the top."""
    data = data.drop(["time"], axis=1)  # get rid of time column
    drop_values = set()
    cols = data.columns
    for i in range(0, data.shape[1]):
        for j in range(0, i + 1):
            # get rid of all diagonal entries and the lower triangular
            drop_values.add((cols[i], cols[j]))
    corrmat = data.corr().unstack()
    # sort by absolute values but keep sign
    corrmat = corrmat.drop(labels=drop_values).sort_values(ascending=False,
                                                           key=lambda col: col.abs())
    return corrmat