11 Converting and grouping data frames

 

This chapter covers

  • Converting data frames to other Julia types
  • Writing type-stable code
  • Understanding type piracy
  • Grouping data frame objects
  • Working with grouped data frames

In chapter 10, we reviewed various ways that DataFrame objects can be constructed from different data sources. In this chapter, we discuss the reverse process and show how you can create other objects from a data frame (recall from chapter 9 that a data frame can be a DataFrame or its view, that is, a SubDataFrame). You might want to perform such an operation in two scenarios.

In the first scenario, you need to perform analytical tasks provided by functions that do not accept a data frame as input, but instead accept another type, so you’d need to convert a data frame to the expected target format. An example is conversion of a data frame to a matrix that you want to use later in linear algebra operations.

11.1 Converting a data frame to other value types

11.1.1 Conversion to a matrix

11.1.2 Conversion to a named tuple of vectors

11.1.3 Other common conversions

11.2 Grouping data frame objects

11.2.1 Preparing the source data frame

11.2.2 Grouping a data frame

11.2.3 Getting group keys of a grouped data frame

11.2.4 Indexing a grouped data frame with a single value

11.2.5 Comparing performance of indexing methods

11.2.6 Indexing a grouped data frame with multiple values

11.2.7 Iterating a grouped data frame

Summary