title: Pandas - Correlation between two dataframes without alignment
body: <p>I need to get the correlation between two dataframes columns. Both of them have the same columns but the correlation is not working because of alignment probably.</p>
  
  <p>I don't really care about the index of the dataframe, i just wan't to correlate the values in the cells, treating each column as a random distribution.</p>
  
  <p>I'm not sure if it's my pandas or my math skills that are lacking, but i don't get what is the purpose of the alignment in this case.</p>
  
  <p><strong>Here is my code:</strong></p>
  
  <pre><code>def correlation(indv1, indv2):
      frame1 = pd.DataFrame(indv1).select_dtypes(include=['float64', 'int64']) # Filtra o individuo para ficar apenas com valores int ou float
      frame2 = pd.DataFrame(indv2).select_dtypes(include=['float64', 'int64'])
      result = frame1.corrwith(frame2)
      return result.sum()
  </code></pre>
  
  <p><strong>Here is what i've tried:</strong></p>
  
  <ul>
  <li>aligning the dataframes with <code>DataFrame.align</code>, but i'm not sure how to do it</li>
  <li>reindexing the dataframes with <code>DataFrame.reindex</code> but it also generates NaN from alignment</li>
  <li>using <code>DataFrame.reset_index</code> but it creates another column with the old indexes</li>
  </ul>
  
  <p><strong>Here is a sample that is going wrong:</strong></p>
  
  <pre><code>test1 = pd.Series(np.random.random(3), index=[0, 1, 2])
  test2 = pd.Series(np.random.random(3), index=[3, 4, 5])
  print(correlation(test1, test2))
  </code></pre>
  
  <p>If you print the result array of the correlation function, it shows NaN.</p>
  
  <p><strong>Here is what i want to do (per column):</strong></p>
  
  <p><a href="https://i.stack.imgur.com/MaSOP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MaSOP.jpg" alt="correlation formula"></a></p>
  
  <p>with X being a value from the cell and mi and sigma being the mean and std. dev. of the column.</p>