import math


def drop_irrelevant_samples(x_y_df, good_data_ratio):
    """
    Drops the samples that have less than the good_data_ratio of non-missing data,
    or that has the target value missing.
    To drop all the samples that have any missing data, use "good_data_ratio=-1"
    """
    x_df = x_y_df.iloc[:, :-1]
    y_df = x_y_df.iloc[:, -1]
    if good_data_ratio < 0:
        x_df = x_df.dropna(how='any', axis=0)
    else:
        x_df = x_df.dropna(thresh=math.ceil(good_data_ratio*x_df.shape[1]), axis=0)
    y_df = y_df.dropna()
    return x_df.join(y_df, how='inner')