Timeline for answer to Create new column based on values from other columns / apply a function of multiple columns, row-wise in Pandas by cottontail
Current License: CC BY-SA 4.0
Post Revisions
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 9, 2025 at 17:33 | history | edited | cottontail | CC BY-SA 4.0 |
case_when could be used
|
| Jan 8, 2023 at 9:27 | comment | added | Karl Knechtel | I'm not entirely convinced of those advantages, either. | |
| Jan 8, 2023 at 0:22 | comment | added | cottontail |
@KarlKnechtel It's not better, just more concise and I guess less error-prone (no need to worry about brackets) and more readable than df['colA'].mul(df['colB']). In terms of performance, it's even worse than mul() or * because it has to do a lot more validation before reduction.
|
|
| Jan 7, 2023 at 20:39 | comment | added | Karl Knechtel |
Is df[['colA','colB']].prod(1) (I infer 1 is the axis argument) better than df['colA'] * df['colB']? Why?
|
|
| Sep 8, 2022 at 4:54 | history | answered | cottontail | CC BY-SA 4.0 |