title: Pandas' diff but user defined function
body: <p>Pandas' <code>pandas.DataFrame.diff</code> almost does what I'm attempting to do.</p>
  
  <p>From the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.diff.html" rel="nofollow noreferrer">documentation</a></p>
  
  <pre><code>&gt;&gt;&gt; df = pd.DataFrame({'a': [1, 2, 3, 4, 5, 6],
  ...                    'b': [1, 1, 2, 3, 5, 8],
  ...                    'c': [1, 4, 9, 16, 25, 36]})
  &gt;&gt;&gt; df
     a  b   c
  0  1  1   1
  1  2  1   4
  2  3  2   9
  3  4  3  16
  4  5  5  25
  5  6  8  36
  </code></pre>
  
  <p><code>df.diff(axis=0)</code> and <code>df.diff(axis=1)</code> respectively produces</p>
  
  <pre><code>&gt;&gt;&gt; df.diff()
       a    b     c
  0  NaN  NaN   NaN
  1  1.0  0.0   3.0
  2  1.0  1.0   5.0
  3  1.0  1.0   7.0
  4  1.0  2.0   9.0
  5  1.0  3.0  11.0
  
  &gt;&gt;&gt; df.diff(axis=1)
      a    b     c
  0 NaN  0.0   0.0
  1 NaN -1.0   3.0
  2 NaN -1.0   7.0
  3 NaN -1.0  13.0
  4 NaN  0.0  20.0
  5 NaN  2.0  28.0
  </code></pre>
  
  <p>What <code>df.diff</code> is doing is essentially applying this function</p>
  
  <pre><code>def diff_func(columns):
      return columns[1:] - columns[0:-1]
  </code></pre>
  
  <p>I want to define my own function, which replace the <code>diff_func</code>.
  What I want to is "apply" my own function (possibly nonlinear) to the consecutive (<code>periods=1</code>) columns/rows. For example, <code>func(x,y) = sin(x)*cos(y)</code> where <code>x,y</code> are consecutive columns or rows of <code>periods=n</code></p>