Performing a excel-like countifs in Pandas
<p>I have a dataset that lists employees and timestamps on which they complete certain actions. It is divided into three columns: Employee, Date, Hour.</p>

<p>I want to count the number of employees that is active each hour. In excel I would do this by adding a fourth column <code>EmpFactor</code> in which I perform a <code>COUNTIFS</code> operation:</p>

<pre><code>=1/COUNTIFS(Name range;Name;Date range;Date;Hour range;Hour)
</code></pre>

<p>I can subsequently calculate the number of active employees by performing a <code>SUMIF</code> on the <code>EmpFactor</code> Column.</p>

<p>I tried the following code to compose the <code>EmpFactor</code> column using pandas:</p>

<pre><code>for name,date,time in zip(df['Employee'],df['Date'],df['Time']):
    df['EmpFactor'] = 1/(df[(df.Employee == name) and (df.Day == dag) 
                             and (df.Time == tijd)].count())
</code></pre>

<p>This however doesn't work. I have searched extensively through numerous topics on SO, but haven't found a fitting answer yet. </p>