title: Count occurencies of a conditional relationship between 2 dataframes and compute correlation
body: <p>I want to find the relationship between elements of different yet connected data frames. Here I have a df that shows friendships: id1 is friends with id2, id3, id4, id5, id21 etc.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;"></th>
  <th style="text-align: center;">friend1</th>
  <th style="text-align: center;">friend2</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">row1</td>
  <td style="text-align: center;">id1</td>
  <td style="text-align: center;">id3</td>
  </tr>
  <tr>
  <td style="text-align: center;">row2</td>
  <td style="text-align: center;">id2</td>
  <td style="text-align: center;">id1</td>
  </tr>
  <tr>
  <td style="text-align: center;">row3</td>
  <td style="text-align: center;">id5</td>
  <td style="text-align: center;">id1</td>
  </tr>
  <tr>
  <td style="text-align: center;">row4</td>
  <td style="text-align: center;">id12</td>
  <td style="text-align: center;">id2</td>
  </tr>
  <tr>
  <td style="text-align: center;">row5</td>
  <td style="text-align: center;">id21</td>
  <td style="text-align: center;">id1</td>
  </tr>
  <tr>
  <td style="text-align: center;">row6</td>
  <td style="text-align: center;">id4</td>
  <td style="text-align: center;">id2</td>
  </tr>
  <tr>
  <td style="text-align: center;">row7</td>
  <td style="text-align: center;">id7</td>
  <td style="text-align: center;">id8</td>
  </tr>
  <tr>
  <td style="text-align: center;">row8</td>
  <td style="text-align: center;">id1</td>
  <td style="text-align: center;">id4</td>
  </tr>
  <tr>
  <td style="text-align: center;">row9</td>
  <td style="text-align: center;">id21</td>
  <td style="text-align: center;">id2</td>
  </tr>
  <tr>
  <td style="text-align: center;">row10</td>
  <td style="text-align: center;">id3</td>
  <td style="text-align: center;">id5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Here is another dataframe where it shows when someone goes to a party. For example, Id5 went to parties on 2012-02-03 and 2012-05-09.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;"></th>
  <th style="text-align: center;">person</th>
  <th style="text-align: center;">date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">row1</td>
  <td style="text-align: center;">id1</td>
  <td style="text-align: center;">2012-02-03</td>
  </tr>
  <tr>
  <td style="text-align: center;">row2</td>
  <td style="text-align: center;">id2</td>
  <td style="text-align: center;">2012-05-09</td>
  </tr>
  <tr>
  <td style="text-align: center;">row3</td>
  <td style="text-align: center;">id5</td>
  <td style="text-align: center;">2012-02-03</td>
  </tr>
  <tr>
  <td style="text-align: center;">row4</td>
  <td style="text-align: center;">id12</td>
  <td style="text-align: center;">2012-05-09</td>
  </tr>
  <tr>
  <td style="text-align: center;">row5</td>
  <td style="text-align: center;">id21</td>
  <td style="text-align: center;">2012-02-03</td>
  </tr>
  <tr>
  <td style="text-align: center;">row6</td>
  <td style="text-align: center;">id7</td>
  <td style="text-align: center;">2012-02-22</td>
  </tr>
  <tr>
  <td style="text-align: center;">row7</td>
  <td style="text-align: center;">id5</td>
  <td style="text-align: center;">2012-05-09</td>
  </tr>
  <tr>
  <td style="text-align: center;">row8</td>
  <td style="text-align: center;">id3</td>
  <td style="text-align: center;">2012-02-22</td>
  </tr>
  <tr>
  <td style="text-align: center;">row9</td>
  <td style="text-align: center;">id8</td>
  <td style="text-align: center;">2012-02-22</td>
  </tr>
  <tr>
  <td style="text-align: center;">row10</td>
  <td style="text-align: center;">id1</td>
  <td style="text-align: center;">2012-02-22</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I want to find the correlation between people attending parties depending on whether their friends attend. For example for id1:</p>
  <p>Went to party 2012-02-03 (same day as id21, id5) and 2012-02-22 (same day as id7, id3, id8). So 2 friends on 1 occasion and 1 on another (<strong>mean=1.5</strong> friends when he attends a party).</p>
  <p>I would like to see the average number of friends existing at a party for each person present in the dataset. If someone has no friends, visited no parties, or visited parties without his friends then the mean will be 0.</p>
  <p>I tried to build this using pandas methods like value_counts/groupby and dictionaries but I lost hope along the way. Thanks in advance for any help.</p>
  <p>Here are the constructors for the dfs:</p>
  <pre><code>index = ['r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r10']
  data1 = {'friend1': ['id1', 'id2','id5','id12','id21','id4','id7','id1','id21', 'id3'],
           'friend2': ['id3', 'id1','id1','id2','id1','id2','id8','id4','id2','id5']}
  data2 = {'person': ['id1', 'id2','id5','id12','id21','id7','id5','id3','id8','id1'],
           'date': ['2012-02-03', '2012-05-09', '2012-02-03', '2012-05-09', '2012-02-03','2012-02-22','2012-05-09','2012-02-22','2012-02-22','2012-02-22']}
  df1 = pd.DataFrame(data1, index=index)
  df2 = pd.DataFrame(data2, index=index)
  </code></pre>