Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save admond1994/81f6a3c714e02b2dd6665267eeafb5c3 to your computer and use it in GitHub Desktop.

Select an option

Save admond1994/81f6a3c714e02b2dd6665267eeafb5c3 to your computer and use it in GitHub Desktop.
def get_discrete_intervals_from_values(df):
'''
AIM -> get discrete intervals by binning values to a range
INPUT -> df
OUTPUT -> updated df with discrete intervals based on numerical values
------
'''
df['rating'] = pd.cut(df['rating'],
bins=[-1,3,5,7,10],
labels=['bad','moderate','good','strong'])
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment