title: Pandas 0.23 groupby and pct change not returning expected value
body: <p>For each <code>Name</code> in the following dataframe I'm trying to find the percentage change from one <code>Time</code> to the next of the <code>Amount</code> column:</p>
  
  <p><a href="https://i.stack.imgur.com/J6imC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J6imC.png" alt="enter image description here"></a></p>
  
  <p>Code to create the dataframe:</p>
  
  <pre><code>import pandas as pd
  
  df = pd.DataFrame({'Name': ['Ali', 'Ali', 'Ali', 'Cala', 'Cala', 'Cala', 'Elena', 'Elena', 'Elena'],
                     'Time': [1, 2, 3, 1, 2, 3, 1, 2, 3],
                     'Amount': [24, 52, 34, 95, 98, 54, 32, 20, 16]})
  
  df.sort_values(['Name', 'Time'], inplace = True)
  </code></pre>
  
  <p>The first approach I tried (based on <a href="https://stackoverflow.com/questions/40273251/pandas-groupby-with-pct-change">this question and answer</a>) used <code>groupby</code> and <code>pct_change</code>:</p>
  
  <pre><code>df['pct_change'] = df.groupby(['Name'])['Amount'].pct_change()
  </code></pre>
  
  <p>With the result:</p>
  
  <p><a href="https://i.stack.imgur.com/Zwtoz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zwtoz.png" alt="enter image description here"></a></p>
  
  <p>This doesn't seem to be grouping by the name because it is the same result as if I had used no <code>groupby</code> and called <code>df['Amount'].pct_change()</code>. According to the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.pct_change.html" rel="nofollow noreferrer">Pandas Documentation</a> for <code>pandas.core.groupby.DataFrameGroupBy.pct_change</code>, the above approach should work to calculate the percentage change of each value to the previous value within a group.</p>
  
  <p>For a second approach I used <code>groupby</code> with <code>apply</code> and <code>pct_change</code>:</p>
  
  <pre><code>df['pct_change_with_apply'] = df.groupby('Name')['Amount'].apply(lambda x: x.pct_change())
  </code></pre>
  
  <p>With the result:</p>
  
  <p><a href="https://i.stack.imgur.com/AK2OH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AK2OH.png" alt="enter image description here"></a></p>
  
  <p>This time all the percentage changes are correct. </p>
  
  <p>Why does the <code>groupby</code> and <code>pct_change</code> approach not return the correct values, but using <code>groupby</code> with <code>apply</code> does?</p>
  
  <p><strong>Edit January 28, 2018</strong>: This behavior has been corrected in the latest version of Pandas, 0.24.0. To install run <code>pip install -U pandas</code>.</p>