title: How to access index inside function for applymap in pandas?
body: <p>I am using a custom function in pandas that iterates over cells in a dataframe, finds the same row in a different dataframe, extracts it as a tuple, extracts a random value from that tuple, and then adds a user specified amount of noise to the value and returns it to the original dataframe.  I was hoping to find a way to do this that uses <code>applymap</code>, is it possible? I couldn't find a way using <code>applymap</code>, so I used <code>itertuples</code>, but an <code>applymap</code> solution should be more efficient.</p>
  <pre><code>import pandas as pd
  # Mock data creation
  key = pd.DataFrame({'col1': [1, 2, 3], 'col2': [4,5,6], 'col3':[7,8,9]})
  results = pd.DataFrame(np.zeros((3,3)))
  
  def apply_value(value):    
      key_index = # &lt;-- THIS IS WHERE I NEED A WAY TO ACCESS INDEX
      key_tup = key.iloc[key_index]
      length = (len(key_tup) - 1)
      random_int = random.randint(1, length)
      random_value = key_tup[random_int]
      return random_value
  
  results = results.applymap(apply_value)
  </code></pre>