title: How do I groupby with one key column, using condition on 2nd column and adding third column separately for weekday and weekend?
body: <p>My dataframe has 3 columns. ID, Day Type (Monday = 0, Sunday = 6), and quantity.</p>
  
  <p>I want to groupby in a way that for each 'Id' I would have 2 rows, one with aggregate quantity of weekdays (M-F) and one for weekend. </p>
  
  <pre><code>Id  Qty  DayType
  B07 581  0
  B07 1096 1
  B07 1245 2
  B07 1080 3
  B07 856  4
  B07 581  5
  B07 1096 6
  B08 1345 0
  B08 1580 3
  B08 816  4
  
  </code></pre>
  
  <p>Expected output </p>
  
  <pre><code>Id  Qty  DayType
  B07 4858 0
  B07 1677 1
  B08 3741 0
  
  </code></pre>
  
  <p>The 0 in the DayType in the output indicates weekday and 1 indicates weekend.</p>
  
  <p>Also, if you can suggest how to pivot it later, that will be even much helpful</p>
  
  <pre><code>id weekday weekend
  B07 4858    1677
  B08 3741    0
  
  </code></pre>
  
  <p>I found a few solutions to groupby based on a condition but in this condition there are two conditions which I cannot figure out how to implement. Thank you. </p>
  
  <hr>
  
  <p>Based on the answer suggested by Ansev, I am getting following output -</p>
  
  <pre><code>Id  Weekdays  Weekend
  B07     20817     3607
  C03     22289     6569
  F05     22807     6474
  </code></pre>
  
  <p>That is correct. </p>
  
  <p>But when I try non-pivot format based on Ansev suggestion in the comment under his answer, I get this -</p>
  
  <pre><code>id        Qty        DayType
  B07       20817       43
  B07        3607       44
  C03       22289       43
  C03        6569       44
  F05       22807       43
  
  </code></pre>
  
  <p>As you can see it is adding up DayType too. I expect 0 and 1 there to represent weekday and weekend. Any suggestion? </p>