title: How to handle pct_change with negative values
body: <p>I am calculating percentage change for a panel dataset, which has both positive and negative values. If both values of n and n+1 date are negative and values of n &gt; n+1, for instance, n=-2, n+1=-4. The calculated percentage change is ((n+1)-n)/n=((-4)-(-2))/-2=1. As you can see the change should be a downtrend, which is expected to be negative but the result is the opposite. I normally set the denominators the absolute values ((n+1)-n)/abs(n) in other software to ensure the direction of the trend. Just wondering if I can do so in Python pandas pct_change to set up the denominator to be absolute values. Many thanks. I have solved the question based on the answer from Leo.</p>
  <p>Here is a data example if one wants to play around.</p>
  <pre><code>import pandas as pd
  df= {'id':[1,1,2,2,3,3],'values':[-2,-4,-2,2,1,5]}
  df=pd.DataFrame(data=df)
  df['pecdiff']=(df.groupby('id')['values'].apply(lambda x:x.diff()/x.abs().shift()
  )).fillna(method=bfill)
  </code></pre>