Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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]
Comment

PREVIOUS NEXT
Code Example
Python :: sort python 
Python :: add horizontal line to plotly scatter 
Python :: Create an array of 10 zeros 
Python :: pandas count show one column 
Python :: if statement in python 
Python :: how to count number of records in json 
Python :: box plot in seaborn 
Python :: django redirect 
Python :: Login script using Python and SQLite 
Python :: python for loop increment 
Python :: python programm zu exe 
Python :: matplotlib 
Python :: python tkinter dynamic toggle button 
Python :: get reactions from message discord.py 
Python :: how to comment code in python 
Python :: dash log scale 
Python :: dict map() 
Python :: numpy find mean of array 
Python :: is in array python 
Python :: django form field class 
Python :: python if elif 
Python :: any python 
Python :: python check None 
Python :: py one line function 
Python :: python treemap example 
Python :: pandas get highest values row 
Python :: pytube get highest resolution 
Python :: python fiboncci 
Python :: move object towards coordinate slowly pygame 
Python :: raise exception without traceback python 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =