I have a pandas dataframe (df) with a column df.age ranging from 0 - 100 years and a column df.haircolor (bright, dark, purple, grey).
Now I want to bin the age in decades:
bins = np.linspace(df.age.min(), df.age.max(), 10)
decades = df.groupby(np.digitize(df.age, bins))
Now I am trying to find a good way to plot this. I'd like a barplot where each haircolor has a bar. Naively I tried that.
df['haircolor'].plot(kind='bar', by=decades)
It is not giving me the result I hoped for. Anyone an idea? thanks.