0

I am trying to assign decile index to each of group of the grouped data individually based on another column which has the amount of that item. However I am shown the error "ValueError: Bin edges must be unique: array([ -12., 1...])" exception".

I referred to : Why use pandas qcut return ValueError: Bin edges must be unique? But this solution generates highly uneven bins (difference between some bin counts almost 1000 records) for my data with some bins having 0 occurrences.

How do I resolve this error?

1 Answers1

0

Let look at at this exmaple:

df = pd.DataFrame({'ID':np.random.choice(list('ABC'),30),
                   'data':np.random.randint(100,500,30)})

df['Performance in Group'] = (df.groupby('ID')['data']
                                .apply(lambda x: pd.qcut(x,3,labels=['Below','Average','Above'])))

Output(head 10 records):

  ID  data Performance in Group
0  A   396                Above
1  A   255              Average
2  C   471                Above
3  C   109                Below
4  B   265              Average
5  C   404              Average
6  A   199                Below
7  C   326              Average
8  C   213                Below
9  C   225              Average
Scott Boston
  • 147,308
  • 15
  • 139
  • 187