<commit_before>---
layout: page
title: "Worked examples"
category: doc
date: 2002-11-01 12:00:00
order: 2
---

## Explaining the recipe a02.py
 
The spreadsheet we're going to extract data from is `a02.xls`. It's
available [here](https://github.com/scraperwiki/eot-recipes) together
with the recipe `a02.py` which we're going to walk through
step-by-step in this tutorial.

We want to extract all the observations from the tabs, *except* the combined
"all aged 16 & over" data and the change data.

** Image: spreadsheet with regions that we want selected highlighted **

### `per_file`

```python
def per_file(tableset):
    return "*"
```
 
This selects all tabs from the spreadsheet, so we will be extracting
data from both the `seasonally adjusted` and the `not seasonally
adjusted` tabs.

In this case, the layouts of the tabs is similar enough that we can use
this recipe for all the tabs.

### `per_tab`

```python
def per_tab(tab):
    obs = tab.filter("MGSL").assert_one().shift(DOWN).fill(RIGHT).fill(DOWN).is_number().is_not_italic()
    tab.col('A').one_of(['Male', 'Female', 'All Persons']).dimension('gender', CLOSEST, ABOVE)
    tab.col('A').is_date().dimension(TIME, DIRECTLY, LEFT)
    tab.regex("All aged .*").dimension('ages', CLOSEST, UP)
    tab.filter("Total economically active").fill(LEFT).fill(RIGHT).is_not_blank().dimension('indicator', DIRECTLY, ABOVE)
    tab.dimension('adjusted_yn', tab.name)
    return obs
```<commit_msg>Explain how to use a02.py example<commit_after>---
layout: page
title: "Worked examples"
category: doc
date: 2002-11-01 12:00:00
order: 2
---

## Explaining the recipe a02.py
 
The spreadsheet we're going to extract data from is `a02.xls`. It's
available [here](https://github.com/scraperwiki/eot-recipes) together
with the recipe `a02.py` which we're going to walk through
step-by-step in this tutorial.

We want to extract all the observations from the tabs, *except* the combined
"all aged 16 & over" data and the change data.

We can run this by placing `a02.py` in the same directory as `a02.xls` and
running `bake a02.py a02.xls` while in that directory at the Windows
command line.

** Image: spreadsheet with regions that we want selected highlighted **

### `per_file`

```python
def per_file(tableset):
    return "*"
```
 
This selects all tabs from the spreadsheet, so we will be extracting
data from both the `seasonally adjusted` and the `not seasonally
adjusted` tabs.

In this case, the layouts of the tabs is similar enough that we can use
this recipe for all the tabs.

### `per_tab`

```python
def per_tab(tab):
    obs = tab.filter("MGSL").assert_one().shift(DOWN).fill(RIGHT).fill(DOWN).is_number().is_not_italic()
    tab.col('A').one_of(['Male', 'Female', 'All Persons']).dimension('gender', CLOSEST, ABOVE)
    tab.col('A').is_date().dimension(TIME, DIRECTLY, LEFT)
    tab.regex("All aged .*").dimension('ages', CLOSEST, UP)
    tab.filter("Total economically active").fill(LEFT).fill(RIGHT).is_not_blank().dimension('indicator', DIRECTLY, ABOVE)
    tab.dimension('adjusted_yn', tab.name)
    return obs
```
{'fraction_non_alphanumeric': 0.13475866537091027, 'fraction_numerical': 0.018140589569160998, 'mean_word_length': 4.594202898550725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '956681', 'n_tokens_mistral': 1078, 'n_tokens_neox': 968, 'n_words': 342}