.groupby(columnName.count)

The groupby count method takes a numeric column, sorts it, and groups into equal ranges sized to have equal numbers of values. For example, to segment all American households by income, groupby on the column income with a count of 10. This will return the top 10,20,30,40,50,60,70,80,90% etc.

Groupby count is a helpful method for creating an even distribution of colors in chloropleth map color scales.

Syntax .groupby(columnName.count: string) Example
  1. var q = ml.query().from('maplarge/Donors');
  2. q.select('Amount.count','Amount.min','Amount.max', 'Amount.key');
  3. q.groupby('Amount.count.10');
  4. q.run(function (data, query);
  5. console.log(data);
  6. });
Demo

This demo shows a way to group political contributions into groups of 10. The groupby method, the Amount.count.10 will return 10 groups of Amount data. If there are 1,000 values in the database it will return 10 groups of 100 values aggregated. This is also a way to get the top and bottom X percent of data.

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. var q = ml.query().from('maplarge/Donors');
  8. q.select('Amount.count','Amount.min','Amount.max', 'Amount.key');
  9. q.groupby('Amount.count.10');
  10. q.orderby('Amount');
  11.  
  12. q.run(function (data, query) {
  13. var dataDiv = document.getElementById("dataDiv");
  14. dataDiv.innerHTML = ml.util.JsonHighlight(data);
  15. });
  16.  
  17. });
  18. </script>
  19. </head>
  20. <body>
  21. <div id="dataDiv">
  22. </div>
  23. </body>
  24. </html>
Special Groupbys