I have a dataframe looks like below:

```
 person    year    Office        Job      rank    
 Harry     2002    Los Angeles   CEO       -1     
 Harry     2006    Boston        CEO       -1     
 Harry     2006    Los Angeles   Advisor   0      
 Harry     2006    Chicago       Chairman  2      

 Peter     2001    New York      Director  -1     
 Peter     2001    Chicago       CFO       3      
 Peter     2001    Chicago       CEO       1      

```

I want to sort the data within the person-year groups. The sorting should be based on the information in the column "rank". For each person-year group with multiple (>1) records, I want to sort the data based on the numeric values in the column "rank" (from small to large) and create a new column called "rank2" to capture the sorted order after sorting (starting from 0).

Thus, the output should look like:

```
 person    year    Office        Job      rank    rank2
 Harry     2002    Los Angeles   CEO       -1     0
 Harry     2006    Boston        CEO       -1     0
 Harry     2006    Los Angeles   Advisor   0      1
 Harry     2006    Chicago       Chairman  2      2

 Peter     2001    New York      Director  -1     0
 Peter     2001    Chicago       CFO       3      2
 Peter     2001    Chicago       CEO       1      1

```