Horje
dataframe cut based on range Code Example
dataframe cut based on range
test = pd.DataFrame({'days': [0,20,30,31,45,60]})

test['range1'] = pd.cut(test.days, [0,30,60], include_lowest=True)
#30 value is in [30, 60) group
test['range2'] = pd.cut(test.days, [0,30,60], right=False)
#30 value is in (0, 30] group
test['range3'] = pd.cut(test.days, [0,30,60])
print (test)
   days          range1    range2    range3
0     0  (-0.001, 30.0]   [0, 30)       NaN
1    20  (-0.001, 30.0]   [0, 30)   (0, 30]
2    30  (-0.001, 30.0]  [30, 60)   (0, 30]
3    31    (30.0, 60.0]  [30, 60)  (30, 60]
4    45    (30.0, 60.0]  [30, 60)  (30, 60]
5    60    (30.0, 60.0]       NaN  (30, 60]




Python

Related
python console width Code Example python console width Code Example
TypeError: Unicode-objects must be encoded before hashing Code Example TypeError: Unicode-objects must be encoded before hashing Code Example
python milisegundos Code Example python milisegundos Code Example
python array of tuples for loop Code Example python array of tuples for loop Code Example
list inside a list in python Code Example list inside a list in python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7