continuous data is often discretized or otherwised separated into "binsfor analysis suppose you have data about group of people in studyand you want to group them into discrete age bucketsin [ ]ages [ let' divide these into bins of to to to and finally and older to do soyou have to use cuta function in pandasin [ ]bins [ in [ ]cats pd cut(agesbinsin [ ]cats out[ ]categoricalarray([( ]( ]( ]( ]( ]( ]( ]( ]( ]( ]( ]( ]]dtype=objectlevels ( )index([( ]( ]( ]( ]]dtype=objectthe object pandas returns is special categorical object you can treat it like an array of strings indicating the bin nameinternally it contains levels array indicating the distinct category names along with labeling for the ages data in the labels attributein [ ]cats labels out[ ]array([ ]in [ ]cats levels out[ ]index([( ]( ]( ]( ]]dtype=objectin [ ]pd value_counts(catsout[ ]( ( ( ( consistent with mathematical notation for intervalsa parenthesis means that the side is open while the square bracket means it is closed (inclusivewhich side is closed can be changed by passing right=falsein [ ]pd cut(ages[ ]right=falseout[ ]categoricalarray([[ )[ )[ )[ )[ )[ )[ )[ )[ )[ )[ )[ )]dtype=objectlevels ( )index([[ )[ )[ )[ )]dtype=objectyou can also pass your own bin names by passing list or array to the labels optionin [ ]group_names ['youth''youngadult''middleaged''senior'in [ ]pd cut(agesbinslabels=group_namesout[ ]data transformation www it-ebooks info