Book Image

Clojure Data Analysis Cookbook

By : Eric Rochester
Book Image

Clojure Data Analysis Cookbook

By: Eric Rochester

Overview of this book

<p>Data is everywhere and it's increasingly important to be able to gain insights that we can act on. Using Clojure for data analysis and collection, this book will show you how to gain fresh insights and perspectives from your data with an essential collection of practical, structured recipes.<br /><br />"The Clojure Data Analysis Cookbook" presents recipes for every stage of the data analysis process. Whether scraping data off a web page, performing data mining, or creating graphs for the web, this book has something for the task at hand.<br /><br />You'll learn how to acquire data, clean it up, and transform it into useful graphs which can then be analyzed and published to the Internet. Coverage includes advanced topics like processing data concurrently, applying powerful statistical techniques like Bayesian modelling, and even data mining algorithms such as K-means clustering, neural networks, and association rules.</p>
Table of Contents (18 chapters)
Clojure Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Filtering datasets with $where


While we can filter datasets before we import them into Incanter, Incanter makes it easy to filter and create new datasets from existing ones. We'll take a look at its query language in this recipe.

Getting ready

We'll use the same dependencies, imports, and data that we did in the Using infix formulas in Incanter recipe.

How to do it…

Once we have the data, we query it using the $where function.

  1. For example, the following creates a dataset with the row for Richmond:

    user=> (def richmond ($where {:NAME "Richmond city"} va-data))
    #'user/richmond
    user=> richmond
    [:GEOID :SUMLEV :STATE :COUNTY :CBSA :CSA :NECTA :CNECTA :NAME :POP100 :HU100 :POP100.2000 :HU100.2000 :P035001 :P035001.2000]
    [5167000 160 51 "" "" "" "" "" "Richmond city" 204214 98349 197790 92282 41304 43649]
  2. The queries can be more complicated, too. The following one picks out the small towns, ones with population less than 1,000:

    user=> (def small ($where {:POP100 {:lte 1000}} va-data))
    #'user...