'Decode all values in a categorical column of pandas data-frame by a specific rule [closed]
Solution 1:[1]
IIUC, you can use:
df['pulse'] = (~df['fault_code'].isin(['B', 'D'])).astype(int)
or taking advantage of boolean -> int equivalence:
df['pulse'] = df['fault_code'].isin(['B', 'D']).rsub(1)
output:
no output as no text data was provided
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 | mozway |

