title: Pandas DataFrame: Apply function cell-wise with index and column values as arguments
body: <p>I am trying to prepare some data for a heatmap or 3D plot. The general idea is that I have some function z=f(x,y) where z is the value of a specific cell with x as its column value and y as its index value.</p>
  
  <p>My current approach is to loop over the dataframe which already shows the desired result:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  
  def my_fun(a, b):
      return(a**2 + b**3)
  
  index = [i for i in np.arange(25.0, 100.0, 25.0)]
  columns = [i for i in np.arange(150.0, 600.0, 150.0)]
  df = pd.DataFrame(np.zeros((3, 3)), index=index, columns=columns)
  
  for idx in index:
      for col in columns:
      df.loc[idx, col] = my_fun(idx, col)
  
  print(df)
  </code></pre>
  
  <p>and yields:</p>
  
  <pre><code>      150.0       300.0       450.0
  25.0  3375625.0  27000625.0  91125625.0
  50.0  3377500.0  27002500.0  91127500.0
  75.0  3380625.0  27005625.0  91130625.0
  </code></pre>
  
  <p>But looping over the dataframe is probably not the right (vectorized) way to deal with this problem and I was looking for some pretty combination of <a href="https://stackoverflow.com/questions/19798153/difference-between-map-applymap-and-apply-methods-in-pandas">apply/applymap/map</a>.</p>
  
  <p>Is there any way to get the same result in a smarter/vectorized way?</p>
  
  <p>Thanks in advance!</p>