Last active
November 22, 2020 08:24
-
-
Save VincentTatan/19911d4a8ddcb10702cf499ddc11e3bf to your computer and use it in GitHub Desktop.
This file contains 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
def fixed_width_cut(df,feature,labels=['Low','Medium','High']): | |
feature_slice, retbins = pd.cut(df[feature], len(labels) ,retbins=True, labels=labels) | |
retbins = [ '%.2f' % elem for elem in retbins ] | |
return feature_slice,retbins | |
def quartile_cut(df,feature,labels=['Low','Medium','High']): | |
feature_slice, retbins = pd.qcut(df[feature], q=len(labels),retbins=True,labels=labels) | |
retbins = [ '%.2f' % elem for elem in retbins ] | |
return feature_slice,retbins | |
# Specified cuts | |
salary_df['average_monthly_hours_bin'], retbins = fixed_width_cut(salary_df,'average_montly_hours',labels=['Low','Medium','High']) | |
salary_df['average_monthly_hours_qbin'], qretbins = quartile_cut(salary_df,'average_montly_hours',labels=['Low','Medium','High']) | |
# Visualize | |
draw_plot(salary_df,['average_monthly_hours_bin','average_monthly_hours_qbin'],'Projects related (Left= fixed width cut, right = quartile cut)',type='countplot') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment