Skip to content

Instantly share code, notes, and snippets.

@jeffbryner
Created October 18, 2019 18:24
Show Gist options
  • Save jeffbryner/fbce8a8ff0fd4874e09257760a25ad96 to your computer and use it in GitHub Desktop.
Save jeffbryner/fbce8a8ff0fd4874e09257760a25ad96 to your computer and use it in GitHub Desktop.
pandas threshold function
def pd_threshold(in_dict,column_name,threshold_count):
'''given a dictionary (or data frame), return a dictionary of the column values over a certain threshold'''
df=pd.DataFrame(in_dict)
df_count=df.groupby(column_name)[column_name].count()
return df_count[df_count.where(df_count>threshold_count)>threshold_count].to_dict()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment