spam = df[df["Label"] == "spam"] ham = df[df["Label"] == "ham"].sample(len(spam), random_state=123) df = pd.concat([ham, spam]).sample(frac=1, random_state=123) df["Label"] = df["Label"].map({"ham": 0, "spam": 1}) __ __