I have a problem turning these intervals into a new column with the categories I want.
I have tried many different variations of the greater than. I did get it to work, by getting the middle bracket to become NaN and then rename them afterwards. The code works fine for line 1 & 3, it is just when I want to create the middle interval that it does not work. I would be forever grateful for any help.
df["AgeGroup"] = df.loc[df["Age"] < 25, "AgeGroup"] = "kid"
df["AgeGroup"] = df.loc[df["Age"] >= 25 & df.loc["Age"] < 50, "AgeGroup"] = "young"
df["AgeGroup"] = df.loc[df["Age"] >= 50, "AgeGroup"] = "old"
Also tried and similar variations. inbetween.
df["AgeGroup"] = df.loc[df["Age"] < 25, "AgeGroup"] = "kid"
df["AgeGroup"] = df.loc[df["Age"] >= 25 < 50, "AgeGroup"] = "young"
df["AgeGroup"] = df.loc[df["Age"] >= 50, "AgeGroup"] = "old"
Varies between syntax errors and The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().