0

Before running pd.cut() my array has values of 0.0 -0.25 0.25 0.50 ... etc after running pd.cut() my array has NaN NaN ... etc I know the problem has to do with how I setup my bins.
I have tried both of the code segments below:

bins = (2, 0.0 , 100)
group_names = ['Bad', 'Good']
array['Values'] = pd.cut(array['Values'], bins=bins, labels=group_names)

bins = (2, 5.0, 100)
group_names = ['Bad', 'Good']
array['Values'] = pd.cut(array['Values'], bins=bins, labels=group_names)

I am expecting the array values to be replaced with Good and Bad. If the array value is greater then 0.0 then Good else Bad

Example:

0.0 -0.25 0.25 0.50
Bad  Bad  Good Bad
Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
DroidWizard
  • 25
  • 1
  • 7
  • 2
    For this, you should use `np.where`: `np.where(array.Values.gt(0), 'Good', 'Bad')`. See: https://stackoverflow.com/a/42848345/4333359 and https://stackoverflow.com/questions/18194404/create-column-with-elif-in-pandas for how to implement `elif` logic – ALollz May 05 '19 at 15:51
  • 1
    Hi @Droid please have look here if you get your answer here https://stackoverflow.com/questions/53080937/pandas-cut-a-series-with-nan-values – shivlal kumavat May 05 '19 at 15:52

0 Answers0