You can create a feature based on a condition with three possible outputs in Python using a conditional statement. Here's an example using the NumPy library:
main.py210 chars10 lines
In this example, we have a NumPy array data
with values [1, 3, 5, 7, 9]
. We create a new feature new_feature
based on the following conditions:
The output will be ['Low' 'Low' 'Medium' 'Medium' 'High']
.
You can modify the conditions and the outputs according to your specific requirements.
gistlibby LogSnag