Brackets(limits, bounds=Bounds.LOW_ONLY, labels=None, first=BracketEnd.CLOSED, last=BracketEnd.CLOSED, others=Unmatched.ERROR)
Source¶
Brackets cutting a number column into categories, used as the format of a TableConversion to CATEGORY.
The categories keep the order of the brackets, so that sorting and plots follow it. A missing value stays missing.
Version history (1)
Added in version 0.1.0
Parameters:
-
limits(list[int | float])The limits between the brackets, at least one, in strictly increasing order. Two limits make one bracket.
-
bounds(Bounds, default:Bounds.LOW_ONLY) -
labels(list[str] | None, default:None)The name of each bracket, in order. When omitted, each name gives the values the bracket holds:
0 to 9for integers,0 to under 10for decimals,80 or moreorunder 0for an open bracket. Whole limits are written without decimals. -
first(BracketEnd, default:BracketEnd.CLOSED)Whether the first bracket stops at the first limit,
BracketEnd.CLOSEDby default, or holds every value below it withBracketEnd.OPEN. -
last(BracketEnd, default:BracketEnd.CLOSED)Whether the last bracket stops at the last limit,
BracketEnd.CLOSEDby default, or holds every value above it withBracketEnd.OPEN. -
others(Unmatched, default:Unmatched.ERROR)
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
EmptyListErrorWhen
limitsis an empty list. -
RefusedSettingError -
InvalidLimitsErrorWhen the limits do not strictly increase, or a single limit has no open end.
-
InvalidLabelCountErrorWhen
labelsdoes not give one name per bracket. -
DuplicateLabelErrorWhen a label appears twice.
Examples:
import numdaplot as ndp
ages = ndp.Array.from_list([4, 17, 30, 92])
victims = ndp.Table.from_arrays({"age": ages})
brackets = ndp.Brackets(limits=[0, 10, 20], last=ndp.BracketEnd.OPEN)
victims.convert(ndp.TableConversion(columns=["age"], dtype=ndp.Type.CATEGORY, format=brackets))
# age
# CATEGORY
# 0 0 to 9
# 1 10 to 19
# 2 20 or more
# 3 20 or more