I asked this question and got a great help. I have a dataframe with multiple columns and 4 years of data and interested in ranks 1 or 2 only.
Name Rank Year
Joe 1 2019
Ben 2 2018
Jo 3 2020
Bo 1 2018
Boo 1 2021
If a name had 1 or 2 rank in a specific year, I want to create a relevant boolean column
Expected output
Name Rank Year If_1st_2018 If_1st_2019 If_1st_first_2020 If_1st_2021 If_2nd_2018 If_2nd_2019 etc
Joe 1 2019 0 1 0 0 0 0
Ben 2 2018 0 0 0 0 1 0
Jo 3 2020 0 0 0 0 0 0
Bo 1 2018 1 0 0 0 0 0
Boo 1 2021 0 0 0 1 0 0
If_1st_2021come from? Is there a 2021 value in the Rank column that you just didn't show?