Skip to content

Instantly share code, notes, and snippets.

@alastairparagas
Created January 13, 2019 21:22
Show Gist options
  • Select an option

  • Save alastairparagas/160ef857ad5dcfd5e1f1ea96a63ba40c to your computer and use it in GitHub Desktop.

Select an option

Save alastairparagas/160ef857ad5dcfd5e1f1ea96a63ba40c to your computer and use it in GitHub Desktop.
joined_df = events.join(indx_date_df.set_index('patient_id'), on='patient_id')
joined_df.indx_date = pd.to_datetime(joined_df.indx_date, format='%Y-%m-%d')
violating_joined_df = joined_df[
(joined_df.indx_date < joined_df.timestamp) |
(joined_df.indx_date - joined_df.timestamp > timedelta(days=2000))
]
joined_df = joined_df[
(joined_df.indx_date >= joined_df.timestamp) &
(joined_df.indx_date - joined_df.timestamp <= timedelta(days=2000))
]
joined_df = joined_df.drop(['event_description', 'timestamp'], axis=1)
joined_df
violators = violating_joined_df.groupby('patient_id')['event_id'].count().reset_index(
name='event_count'
).sort_values(by='event_count')
violators[~violators.patient_id.isin(joined_df.patient_id)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment