Guest User

Untitled

a guest
Oct 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. ##########################################
  2. # each bin is equally filled and cut based on quantiles
  3.  
  4. def qcut(array, number_of_bins):
  5. import pandas as pd
  6. from scipy import stats
  7. bins = stats.mstats.mquantiles(array, [i/number_of_bins for i in range(number_of_bins+1)])
  8. labels = list(range(number_of_bins))
  9. return pd.cut(array, bins, labels = labels).fillna(0)
Add Comment
Please, Sign In to add comment