Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

np where pandas with 3 choices

col         = 'consumption_energy'
conditions  = [ df2[col] >= 400, (df2[col] < 400) & (df2[col]> 200), df2[col] <= 200 ]
choices     = [ "high", 'medium', 'low' ]
    
df2["energy_class"] = np.select(conditions, choices, default=np.nan)


  consumption_energy energy_class
0                 459         high
1                 416         high
2                 186          low
3                 250       medium
4                 411         high
5                 210       medium
6                 343       medium
7                 328       medium
8                 208       medium
9                 223       medium
Comment

PREVIOUS NEXT
Code Example
Python :: tanimoto coefficient rdkit 
Python :: modbusfc03 python 
Python :: golng open file append 
Python :: import cmath python 3 
Python :: python boolean ungleich 
Python :: check is symmetric python 
Python :: range coding 
Python :: xpath h4 contains text 
Python :: python numpy 
Python :: nested list comprehensions 
Python :: plotly colors 
Python :: how to do square roots in python 
Python :: pandas rename column values 
Python :: python inspect module 
Python :: python code for finding prime numbers 
Python :: download youtube video by python 
Python :: mainloop tkinter 
Python :: remove list of value from list python 
Python :: python set union 
Python :: flask socketio send 
Python :: python official documentation 
Python :: prime numbers 1 to 100 
Python :: Python program to calculate area of a rectangle using function 
Python :: python ternary operators 
Python :: positive and negative number in python 
Python :: array and list in python 
Python :: how to load pretrained model in pytorch 
Python :: reading an image using opencv library 
Python :: tkinter filedialog 
Python :: activate venv in python 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =