Created
March 24, 2018 02:46
-
-
Save breeko/fc4001e120b7f2433e569008dda58eaa 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
| # Create next grade date | |
| df["NEXT_GRADE_DATE"] = df.GRADE_DATE.shift() | |
| # Remove next grade date for most recent grades | |
| df.loc[df.drop_duplicates("KEY").index,"NEXT_GRADE_DATE"] = pd.NaT | |
| df["TIME_AT_GRADE"] = df.NEXT_GRADE_DATE - df.GRADE_DATE | |
| f, ax = plt.subplots(figsize=(10,5)) | |
| for grade, color in colors.items(): | |
| days_at_grade = df[(~df.TIME_AT_GRADE.isna()) & (df.GRADE == grade)].TIME_AT_GRADE.dt.days | |
| if days_at_grade.size > 0: | |
| ax.hist(days_at_grade, color=color, label=grade, alpha=0.5, bins=100, weights=np.zeros_like(days_at_grade) + 1. / days_at_grade.size) | |
| ax.legend() | |
| f.tight_layout() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment