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

Normalizing dates and times


One difficult issue when normalizing and cleaning up data is dealing with time. People enter dates and times in a bewildering variety of formats, some of them ambiguous. But we have to do our best to interpret them and normalize them into a standard format.

In this recipe, we'll define a function that attempts to parse a date into a standard string format. We'll use the Clojure clj-time library, which is a wrapper around the Joda Java library (http://joda-time.sourceforge.net/).

Getting ready

First we need to declare our dependencies in the Leiningen project.clj file as shown in the following code snippet:

  :dependencies [[org.clojure/clojure "1.4.0"]
                 [clj-time "0.4.4"]]

And, we need to load those into the our script or REPL. This can be done using the following code snippet:

(use '[clj-time.core :exclude (extend)]
     '[clj-time.format])

How to do it…

To solve this problem of dealing with time, we'll specify a sequence of date/time formats and walk...