|
| 1 | +--- |
| 2 | +title: Exploring Data with OpenRefine |
| 3 | +teaching: 15 |
| 4 | +exercises: 20 |
| 5 | +--- |
| 6 | + |
| 7 | +::::::::::::::::::::::::::::::::::::::: objectives |
| 8 | + |
| 9 | +- Learn about different types of facets and how they can be used to summarise data of different data types |
| 10 | + |
| 11 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 12 | + |
| 13 | +:::::::::::::::::::::::::::::::::::::::: questions |
| 14 | + |
| 15 | +- How can we summarise our data? |
| 16 | +- How can we find errors in our data? |
| 17 | +- How can we edit data to fix errors? |
| 18 | +- How can we convert column data from one data type to another? |
| 19 | + |
| 20 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 21 | + |
| 22 | +## Exploring data with facets |
| 23 | + |
| 24 | +Facets are one of the most useful features of OpenRefine. Data faceting is a process of exploring data by applying multiple filters to investigate its composition. It also allows you to identify a subset of data that you wish to change in bulk. |
| 25 | + |
| 26 | +A `facet` groups all the like values that appear in a column, and allows you to filter the data by those values. It also allows you to edit values across many records at the same time. |
| 27 | + |
| 28 | +### Exploring text columns |
| 29 | + |
| 30 | +One type of facet is called a 'Text facet'. This groups all the identical text values in a column and lists each value with the number of records it appears in. The facet information always appears in the left hand panel in the OpenRefine interface. |
| 31 | + |
| 32 | +Here we will use faceting to look for potential errors in data entry in the `scientificName` column. |
| 33 | + |
| 34 | +1. Scroll over to the `scientificName` column. |
| 35 | + |
| 36 | +2. Click the down arrow and choose `Facet` > `Text facet`. |
| 37 | + |
| 38 | + {alt='Facet menu of a column'} |
| 39 | + |
| 40 | +3. In the left panel, you'll now see a box containing every unique value in the `scientificName` column |
| 41 | + along with a number representing how many times that value occurs in the column. |
| 42 | + |
| 43 | + {alt='Faceting results on the column scientificName'} |
| 44 | + |
| 45 | +4. Try sorting this facet by name and by count. Do you notice any problems with the data? What are they? |
| 46 | + |
| 47 | +5. Hover the mouse over one of the names in the `facet` list. You should see that you have an `edit` function available. |
| 48 | + |
| 49 | +6. You could use this to fix an error immediately, and OpenRefine will ask whether you want to make the same correction to every value it finds like that one. But OpenRefine offers even better ways to find and fix these errors, which we'll use instead. We'll learn about these when we talk about clustering. |
| 50 | + |
| 51 | +::::::::::::::::::::::::::::::::::::::::: callout |
| 52 | + |
| 53 | +## Facets and large datasets |
| 54 | + |
| 55 | +Facets are intended to group together common values and OpenRefine limits the number of values allowed in a single facet to ensure the software does not perform slowly or run out of memory. If you create a facet where there are many unique values (for example, a facet on a 'book title' column in a data set that has one row per book) the facet created will be very large and may either slow down the application, or OpenRefine will not create the facet. |
| 56 | + |
| 57 | + |
| 58 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 59 | + |
| 60 | +::::::::::::::::::::::::::::::::::::::: challenge |
| 61 | + |
| 62 | +## Exercise |
| 63 | + |
| 64 | +1. Using faceting, find out how many years are represented in the census. |
| 65 | +2. Which years have the most and least observations? |
| 66 | +3. Is the column formatted as Number, Date, or Text? |
| 67 | + |
| 68 | +::::::::::::::: solution |
| 69 | + |
| 70 | +## Solution |
| 71 | + |
| 72 | +1. For the column `yr` do `Facet` > `Text facet`. A box will appear in the left panel showing that there are 16 unique entries in this column. |
| 73 | +2. After creating a facet, click `Sort by count` in the facet box. The year with the most observations is 1978. The least is 1993. |
| 74 | +3. By default, the column `yr` is formatted as Text. |
| 75 | + |
| 76 | +::::::::::::::::::::::::: |
| 77 | + |
| 78 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 79 | + |
| 80 | +### Exploring numeric columns |
| 81 | + |
| 82 | +When a table is imported into OpenRefine, all columns are treated as having text values. We can transform columns to other data types (e.g. number or date) using the `Edit cells` > `Common transforms` feature. Here we will experiment changing columns to numbers and see what additional capabilities that grants us. |
| 83 | + |
| 84 | +#### Numeric facet |
| 85 | + |
| 86 | +Sometimes there are non-number values or blanks in a column which may represent errors in data entry and we want to find them. We can do that with a `Numeric facet`. |
| 87 | + |
| 88 | +Create a `numeric facet` for the column `yr`. The facet will be empty because OpenRefine sees all the values as text. |
| 89 | + |
| 90 | +To transform cells in the `yr` column to numbers, click the down arrow for that column, then `Edit cells` > `Common transforms…` > `To number`. You will notice the `yr` values change from left-justified to right-justified, and black to green color. |
| 91 | + |
| 92 | +::::::::::::::::::::::::::::::::::::::: challenge |
| 93 | + |
| 94 | +## Exercise |
| 95 | + |
| 96 | +The dataset included other numeric columns that we will explore in this exercise: |
| 97 | + |
| 98 | +- `period` - Unique number assigned to each survey period |
| 99 | +- `plot` - Plot number animal was caught on, from 1 to 24 |
| 100 | +- `recordID` - Unique record ID number to facilitate quick reference to particular entry |
| 101 | + |
| 102 | +Transform the columns `period`, `plot`, and `recordID` from text to numbers. |
| 103 | + |
| 104 | +1. How does changing the format change the faceting display for the `yr` column? |
| 105 | +2. Can all columns be transformed to numbers? |
| 106 | + |
| 107 | +::::::::::::::: solution |
| 108 | + |
| 109 | +## Solution |
| 110 | + |
| 111 | +Displaying a `Numeric facet` of `yr` shows a histogram of the number of |
| 112 | +entries per year. Notice that the data is shown as a number, not a date. If you instead transform the column to a date, the program will assume all entries are on January 1st of the year. |
| 113 | + |
| 114 | +Only observations that include only numerals (0-9) can be transformed to numbers. If you apply a number transformation to a column that doesn't meet this criteria, and then click the Undo / Redo tab, you will see a step that starts with Text transform on 0 cells. This means that the data in that column was not transformed. |
| 115 | + |
| 116 | +::::::::::::::::::::::::: |
| 117 | + |
| 118 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 119 | + |
| 120 | +The next exercise will explore what happens when a numeric column contains values that are not numbers. |
| 121 | + |
| 122 | +::::::::::::::::::::::::::::::::::::::: challenge |
| 123 | + |
| 124 | +## Exercise |
| 125 | + |
| 126 | +1. For a column you transformed to numbers, edit one or two cells, replacing the numbers with text (such as `abc`) or blank (no number or text). |
| 127 | +2. Use the pulldown menu to apply a numeric facet to the column you edited. The facet will appear in the left panel. |
| 128 | +3. Notice that there are several checkboxes in this facet: `Numeric`, `Non-numeric`, `Blank`, and `Error`. Below these are counts of the number of cells in each category. You should see checks for `Non-numeric` and `Blank` if you changed some values. |
| 129 | +4. Experiment with checking or unchecking these boxes to select subsets of your data. |
| 130 | + |
| 131 | + |
| 132 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 133 | + |
| 134 | +When done examining the numeric data, remove this facet by clicking the `x` in the upper left corner of its panel. Note that this does not undo the edits you made to the cells in this column. |
| 135 | + |
| 136 | +#### Examine a pair of numeric columns using scatterplots |
| 137 | + |
| 138 | +Now that we have multiple columns representing numbers, we can see how they relate to one another using the scatterplot facet. Select a numeric column, for example `recordID`, and use the pulldown menu to > `Facet` > `Scatterplot facet`. A new window called `Scatterplot Matrix` will appear. There are squares for each pair of numeric columns organized in an upper right triangle. Each square has little dots for the cell values from each row. |
| 139 | + |
| 140 | +{alt='Scatterplots between numeric columns'} |
| 141 | + |
| 142 | +Click the image of the scatterplot between `recordID` and `yr` to select this one for the facet. |
| 143 | + |
| 144 | +::::::::::::::::::::::::::::::::::::::: challenge |
| 145 | + |
| 146 | +## Exercise |
| 147 | + |
| 148 | +Click in the scatterplot facet in the lower left margin and drag to highlight a rectangle. How does this change the data rows displayed? |
| 149 | + |
| 150 | + |
| 151 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 152 | + |
| 153 | +::::::::::::::::::::::::::::::::::::::::: callout |
| 154 | + |
| 155 | +## More Details on Faceting |
| 156 | + |
| 157 | +Full documentation on faceting can be found at [Exploring facets: Faceting](https://docs.openrefine.org/manual/facets) |
| 158 | + |
| 159 | + |
| 160 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 161 | + |
| 162 | +:::::::::::::::::::::::::::::::::::::::: keypoints |
| 163 | + |
| 164 | +- Faceting can identify errors or outliers in data |
| 165 | + |
| 166 | +:::::::::::::::::::::::::::::::::::::::::::::::::: |
| 167 | + |
| 168 | + |
0 commit comments