'How to take positions from np.where
I created a dataframe of booleans, and i want to extract the values that are equal to True, and modify it in the original dataframe.
up_val=(np.where(up['Balls']==True))
up_val
output: array([26, 28, 35, 36, 38], dtype=int64)
Then I want to go to original dataframe and modify for that column, the values with index equal to 26, 28, 35, 36, 38; to put a value in this position, but i don't know how to make this step.
Thanks
Solution 1:[1]
Assuming up_val is a pandas DataFrame:
up_val=(np.where(up['Balls']==True))
# now if you want to change these rows in the column to 99
up['Balls'].iloc[up_val[0]] = 99
The index behind up_val is necessary because np.where returns a tuple.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | LukasNeugebauer |
