Skip to content

Instantly share code, notes, and snippets.

@breeko
Created March 24, 2018 02:46
Show Gist options
  • Select an option

  • Save breeko/fc4001e120b7f2433e569008dda58eaa to your computer and use it in GitHub Desktop.

Select an option

Save breeko/fc4001e120b7f2433e569008dda58eaa to your computer and use it in GitHub Desktop.
# 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