Pandas Percent Change on Non-Descending Cells
<p>I'm new to Pandas and Stack Overflow, so please bear with me. I'm trying to calculate the percent change on two times (e.g., for a race, not time of day). So suppose I have five athletes. I've formatted the .csv to give me something like the following:</p>

<pre><code>In [3]: df
Out [3]:
          Athlete     Time  Seconds   
1           Gavin  0:17:00     1020   
2            Noah  0:17:45     1065   
3           Chris  0:18:46     1126
4           David  0:21:40     1300         
5          Travis  0:23:11     1391
</code></pre>

<p>I used a function to convert the times to seconds to make the next step easier, but if I don't need to do this please let me know. What I'm wondering is how to calculate the percent difference from some specified person who might not be first (i.e., the change won't be descending from the fastest time). I'd like to be able to enter a name and have it calculate from that. So if I picked 'Chris', the output would be the following:</p>

<pre><code>          Athlete     Time  Seconds    Percent_Diff
1           Gavin  0:17:00     1020            -9.4
2            Noah  0:17:45     1065            -5.4
3           Chris  0:18:46     1126               0
4           David  0:21:40     1300            15.5
5          Travis  0:23:11     1391            23.5
</code></pre>

<p>I've found this way to choose a row by name:</p>

<pre><code>(df1.loc[df1['Athlete'] == 'Chris']['Seconds'])
</code></pre>

<p>This produces the row for Chris. Is there a way for me to use pct_change() for this, regardless of which name I choose? How do I do this? Thanks!  </p>

<pre><code>df1['pct_diff'] = df['seconds'] / df.loc['Chris', 'seconds'] - 1
</code></pre>

python pandas