title: Pandas column is the sum if three criteria are met (similar to sumproduct)
body: <p>I am trying to create a new column which values are the sum of another column but only if two column contain a specific value.</p>
  
  <p><strong>origin_data_frame (df_o)</strong></p>
  
  <pre><code>month   state       count
  2015-12 Alabama     31359
  2015-12 Alaska      245
  2015-12 Arizona     2940
  2015-12 Arkansas    4076
  2015-12 California  119166
  2015-12 Colorado    3265
  2015-12 Connecticut 12190
  2015-12 Delaware    297
  2015-12 DC          16
  ....... ...         ..
  </code></pre>
  
  <p><strong>target_data_frame (df_t)</strong> ('counts' is not there):</p>
  
  <pre><code>   level_0          level_1        Veterans, 2011-2015  counts
  0  h_pct_vet        California     1777410              &lt;?&gt;
  1  h_pct_vet        Texas          1539655              &lt;?&gt;  
  2  h_pct_vet        Florida        1507738              &lt;?&gt;
  3  h_pct_vet        Pennsylvania   870770               &lt;?&gt; 
  4  h_pct_vet        New York       828586               &lt;?&gt;
  5  l_pct_vet        Vermont        44708                &lt;?&gt;
  6  l_pct_vet        Wyoming        48505                &lt;?&gt;
  </code></pre>
  
  <p><strong>the problem:</strong></p>
  
  <p><em>counts</em> should include a value that is the sum of count if month is between '2011-01' and '2015-12' and state equals "level_1".</p>
  
  <p>I can get a sum for all count in the time frame:</p>
  
  <pre><code>counts_2011_2015 = df_o['count'][(df_o['month'] &gt;= '2011-01-01') &amp; (df_o['month'] &lt;= '2015-12-31')].sum()
  </code></pre>
  
  <p>What I tried so far but without success:</p>
  
  <pre><code>df_t['counts'] = df_o['count'][(df_o['month'] &gt;= '2011-01-01') &amp; (df_o['month'] &lt;= '2015-12-31') &amp; (df_o['state'] == df_t['level_1'])].sum()
  </code></pre>
  
  <p>It raises a ValueError: "ValueError: Can only compare identically-labeled Series objects". </p>
  
  <p>What I found so far (dropping indexes) is not helpful so I would be thankful if someone has an idea</p>