'Using if to compare column values
Here's my df, labeled "Task".
| Country | Confirmed | Ratio | |
|---|---|---|---|
| 1 | Austria | 2510071 | 28.2 |
| 2 | Bolivia | 888175 | 7.8 |
I am required to use an if-else statement to do two things: (1) determine which value in the "Ratio" column is greater, and (2) create a new column that says either "Highest" or "Lowest" for the appropriate observation.
I've read dozens of posts about using if-else, but I cannot seem to find examples of a condition that says "see if the 'Ratio' value in this row is greater or lesser than the 'Ratio' value in another row". I've made lots of if() attempts, but they've all failed pretty miserably.
My goal is code that'll produce this output:
| Country | Confirmed | Ratio | Rank | |
|---|---|---|---|---|
| 1 | Austria | 2510071 | 28.2 | Highest |
| 2 | Bolivia | 888175 | 7.8 | Lowest |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
