'Data labeling by df columns with using ternary operation in pandas
I have the code below that does not work as I want but the mean is clear I guess. In pandas normally we can labeling with df["Label] = df["Column1"] > df["Column2"] like this. However, when I try labeling with ternary as below, it does not work as I expected. Is there any way to do this with ease?
df["Label"] = "1" if df["Column1"] > df["Column2"] else "2"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
