title: How to filter and group pandas DataFrame to get count for combination of two columns
body: <p>I am sorry I could not fit the whole problem in the Title in a concise way. Pardon my English. I will explain my problem with an example.</p>
  <p>Say I have this dataset:</p>
  <pre><code>dff = pd.DataFrame(np.array([[&quot;2020-11-13&quot;, 0, 3,4], [&quot;2020-10-11&quot;, 1, 3,4], [&quot;2020-11-13&quot;, 2, 1,4],
                               [&quot;2020-11-14&quot;, 0, 3,4], [&quot;2020-11-13&quot;, 1, 5,4], 
                               [&quot;2020-11-14&quot;, 2, 2,4],[&quot;2020-11-12&quot;, 1, 1,4],[&quot;2020-11-14&quot;, 1, 2,4],[&quot;2020-11-15&quot;, 2, 5,4],
                               [&quot;2020-11-11&quot;, 0, 1,2],[&quot;2020-11-15&quot;, 1, 1,2],
                               [&quot;2020-11-18&quot;, 1, 2,4],[&quot;2020-11-17&quot;, 0, 1,2],[&quot;2020-11-20&quot;, 0, 3,4]]), columns=['Timestamp', 'ID', 'Name', &quot;slot&quot;])
  </code></pre>
  <p>I want to have a count for each <code>Name</code> and <code>slot</code> combination but disregard multiple timeseries value for same ID. For example, if I simply group by <code>Name</code> and <code>slot</code> I get:</p>
  <pre><code>dff.groupby(['Name', &quot;slot&quot;]).Timestamp.count().reset_index(name=&quot;count&quot;)
  
  
    Name slot count
      1   2   3
      1   4   2
      2   4   3
      3   4   4
      5   4   2
  </code></pre>
  <p>However, for <code>ID == 0</code>, there are two combinations for <code>name == 1</code> and <code>slot == 2</code>, so instead of <code>3</code> I want the count to be <code>2</code>.</p>
  <p>This is the table I would ideally want.</p>
  <pre><code>  Name slot count
      1   2   2
      1   4   2
      2   4   2
      3   4   2
      5   4   2
  </code></pre>
  <p>I tried:</p>
  <pre><code>filter_one = dff.groupby(['ID']).Timestamp.transform(min)
  dff1 = dff.loc[dff.Timestamp == filter_one]
  dff1.groupby(['Name', &quot;slot&quot;]).Timestamp.count().reset_index(name=&quot;count&quot;)
  </code></pre>
  <p>But this gives me:</p>
  <pre><code>  Name slot count
      1   2   1
      1   4   1
      3   4   1
  </code></pre>
  <p>It also does not work if I drop duplicates for <code>ID</code>.</p>