0

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"
  • 1
    Does this answer your question? [Pandas conditional creation of a series/dataframe column](https://stackoverflow.com/questions/19913659/pandas-conditional-creation-of-a-series-dataframe-column) – Pierre D Apr 08 '22 at 01:23
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 08 '22 at 11:55

0 Answers0