title: How to use groupby and .loc to filter dataframe sequentially
body: <p>I have a large dataframe that contains information about food items. For example:</p>
  
  <pre><code>     Year    Journal    Subscription    Known_author
  0    2014       A            1               1
  1    2014       A            1               0 
  2    2014       B            0               1
  3    2014       C            1               0
  4    2015       A            1               1
  5    2015       B            1               1
  6    2015       C            0               1
  7    2015       D            0               0
  </code></pre>
  
  <p>I want to be able to group by year and create a table that contains (1) the number of unique journals per year, (2) number of unique journals that have a subscription, and (3) number of unique journals that have a subscription and a known author.</p>
  
  <p>This would be the table that I am looking for in this scenario:</p>
  
  <pre><code>Year   (1) Column         (2) Column      (3) Column
  2014       3                   2               1
  2015       4                   2               2 
  </code></pre>
  
  <p>I have used:</p>
  
  <p>(1) <code>df.groupby('Pub_Date_Year')['Journal'].agg('nunique')</code> for the first column </p>
  
  <p>(2) <code>df.loc[(df['Subscription']==1)&amp;(df['Year']==2014),'Journal'].agg(['nunique']).values[0]</code></p>
  
  <p>(3) <code>df.loc[(df['Subscription']==1)&amp;(df['Known_author']==1)&amp;(df['Year']==2014),'Journal'].agg(['nunique']).values[0]</code></p>
  
  <p>However, I would want this table to be created in one go, I'm assuming using groupby, aggregate and some sort of lambda function. The ultimate idea is to automate this process as we get more data in, and not have to rely on manually changing the year in the df.loc code. </p>
  
  <p>Is there a way this could be done?</p>