One more question on Pandas. I have a dataframe called df
, one column of which is called age_year
and contains ages of different people from 20 to 70 years old. I need to group all those ages into 4 groups and visualize later basing on another criteria all those people have in a dataframe. However when i write a function and then try to pipe()
it for my groupby method, it throws "Truth value" error.
def age_group(series):
if df["age_year"] < 40:
df["age_young"] = df["age_year"]
elif df["age_year"] > 40 & df["age_year"] < 50:
df["age_40"] = df["age_year"]
elif df["age_year"] > 50 & df["age_year"] < 60:
df["age_50"] = df["age_year"]
else:
df["age_60"] = df["age_year"]
df.groupby('age_year').pipe(age_group("age_year"))