Book Image

Practical Data Science Cookbook

By : Tony Ojeda, Sean Patrick Murphy, Benjamin Bengfort, Abhijit Dasgupta
Book Image

Practical Data Science Cookbook

By: Tony Ojeda, Sean Patrick Murphy, Benjamin Bengfort, Abhijit Dasgupta

Overview of this book

<p>As increasing amounts of data is generated each year, the need to analyze and operationalize it is more important than ever. Companies that know what to do with their data will have a competitive advantage over companies that don't, and this will drive a higher demand for knowledgeable and competent data professionals.</p> <p>Starting with the basics, this book will cover how to set up your numerical programming environment, introduce you to the data science pipeline (an iterative process by which data science projects are completed), and guide you through several data projects in a step-by-step format. By sequentially working through the steps in each chapter, you will quickly familiarize yourself with the process and learn how to apply it to a variety of situations with examples in the two most popular programming languages for data analysis—R and Python.</p>
Table of Contents (18 chapters)
Practical Data Science Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Importing employment data into R


Our first step in this project is to import the employment data into R so that we can start assessing the data and perform some preliminary analysis.

Getting ready

You should be ready to go ahead after completing the previous recipe.

How to do it…

The following steps will guide you through two different ways of importing the CSV file:

  1. We can directly load the data file into R (even from the compressed version) using the following command:

    ann2012 <- read.csv(unz('2012_annual_singlefile.zip','2012.annual.singlefile.csv'),stringsAsFactors=F)
    

    However, you will find that this takes a very long time with this file. There are better ways.

  2. We chose to import the data directly into R since there are further manipulations and merges we will do later. We will use the fread function from the data.table package to do this:

    library(data.table)
    ann2012 <- fread('data/2012.annual.singlefile.csv')
    

    That's it. Really! It is also many times faster than the other method. It...