Is there a way to discretize a column from a Pandas dataframe based on custom limits (meaning the ranges are not of equal length)? Previous questions asked here don't cover this case.
For example, assume we want to convert numeric grades (out of 4) into bins as follows:
3.75 to 4: Excellent
3.5 to 3.75: Very good
3.25 to 3.5: Good
3 to 3.25: Average
2.5 to 3: Bad
Below 2.5: Very bad
I know it can be done using a series of if
s and else
s, but I was looking for a cleaner and more flexible (for higher number of bins) way to do that.