title: Python pandas groupby, sum and select 5 elements
body: <p>I'm trying to get all elements by date value and sum all cost and plot them on stacked bar using pandas module. Here is an example list of dictionaries</p>
  <pre><code>cost_data = [{
      &quot;usage_start_date&quot;: &quot;2022-02-14&quot;,
      &quot;cost&quot;: 10,
      &quot;service_name&quot;: &quot;Service 1&quot;
    },
    {
      &quot;usage_start_date&quot;: &quot;2022-02-14&quot;,
      &quot;cost&quot;: 10,
      &quot;service_name&quot;: &quot;Service 1&quot;
    },
    {
      &quot;usage_start_date&quot;: &quot;2022-02-14&quot;,
      &quot;cost&quot;: 25,
      &quot;service_name&quot;: &quot;Service 2&quot;
    },
    {
      &quot;usage_start_date&quot;: &quot;2022-02-14&quot;,
      &quot;cost&quot;: 2,
      &quot;service_name&quot;: &quot;Service 3&quot;
    },
    {
      &quot;usage_start_date&quot;: &quot;2022-02-14&quot;,
      &quot;cost&quot;: 2,
      &quot;service_name&quot;: &quot;Service 3&quot;
    },
    {
      &quot;usage_start_date&quot;: &quot;2022-02-14&quot;,
      &quot;cost&quot;: 2,
      &quot;service_name&quot;: &quot;Service 4&quot;
    }
  ]
  </code></pre>
  <p>how i can select for example only 2 elements which costs are above then 10, sum all cost of service and group them by usage_start_date using pandas module?
  currently what i have done is to group all elements by usage_start_date and sum the costs</p>
  <pre><code>df = pd.DataFrame(cost_data)
  
  g = df.groupby(['usage_start_date', 'service_name'], as_index=False, group_keys=True).sum()
  g.pivot(index=&quot;usage_start_date&quot;, columns=&quot;service_name&quot;, values=&quot;cost&quot;).plot(kind=&quot;bar&quot;, stacked=True, width=0.2)
  </code></pre>