Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Slice Age in Python

>>> pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]), 3, retbins=True)
([(0.191, 3.367], (0.191, 3.367], (0.191, 3.367], (3.367, 6.533], (6.533, 9.7], (0.191, 3.367]]
Categories (3, object): [(0.191, 3.367] < (3.367, 6.533] < (6.533, 9.7]],
array([ 0.1905    ,  3.36666667,  6.53333333,  9.7       ]))
>>> pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]), 3, labels=["good","medium","bad"])
[good, good, good, medium, bad, good]
Categories (3, object): [good < medium < bad]
>>> pd.cut(np.ones(5), 4, labels=False)
array([1, 1, 1, 1, 1], dtype=int64)
Comment

PREVIOUS NEXT
Code Example
Python :: saving data in python 
Python :: mak a scipy csr sparse matrix 
Python :: bootstrap 5 in django 
Python :: hewwo world 
Python :: take input from clipboard python 
Python :: ternary operator using dictionary in Python 
Python :: python generator for reading and writing file 
Python :: ascending order in python using bubble sort 
Python :: python assertRaises with class property 
Python :: python remove xa0 
Python :: pandas turn counts into probability 
Python :: pandas read csv read all columns except few columns 
Python :: qmenu hide python 
Python :: n largest python 
Python :: vars() python 
Python :: pyplot save image 
Python :: python object has no attribute 
Python :: python polymorphism 
Python :: dataframe change column types 
Python :: sort list of list of dictionaries python 
Python :: whatsapp bot python code 
Python :: bounding box in matplotlib 
Python :: select python interpreter vscode 
Python :: how to access variable of one function in another function in python 
Python :: how to sort nested list in python 
Python :: list inside a list in python 
Python :: how to add items in list in python 
Python :: IndexError: list assignment index out of range 
Python :: def rectangles 
Python :: initialize 2d array of zeros python 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =