Created
March 24, 2018 02:13
-
-
Save breeko/eecec87e80e578f0962986e30955335b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| f, ax = plt.subplots(figsize=(10,5)) | |
| df["YEAR"] = df.GRADE_DATE.dt.year | |
| gb = df[["YEAR", "GRADE","SCORE"]].groupby(["YEAR","GRADE"]).agg("count") | |
| gb["perc"] = gb / gb.sum(level=0) | |
| for year in df.YEAR.unique(): | |
| bottom = 0 | |
| for grade in sorted(df.GRADE.unique()): | |
| perc = gb[(gb.index.get_level_values(0) == year) & (gb.index.get_level_values(1) == grade)].perc | |
| if len(perc) > 0: | |
| perc = perc.values[0] | |
| ax.bar(year, perc, bottom=bottom, color=colors[grade]) | |
| bottom += perc | |
| ax.legend(sorted(df.GRADE.unique()), bbox_to_anchor=(1.25,1), loc="upper right") | |
| ax.set_title("Ratings over time") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment