<commit_before>==================
Compute new values
==================

Change
======

.. code-block:: python

    new_table = table.compute([
        ('2000_change', Change('2000', '2001')),
        ('2001_change', Change('2001', '2002')),
        ('2002_change', Change('2002', '2003'))
    ])

Or, better yet, compute the whole decade using a loop:

.. code-block:: Python

    computations = []

    for year in range(2000, 2010):
        change = Change(year, year + 1)
        computations.append(('%i_change' % year, change))

    new_table = table.compute(computations)

Percent change
==============<commit_msg>Added a cookbook entry on how to use the Percent computation<commit_after>==================
Compute new values
==================

Change
======

.. code-block:: python

    new_table = table.compute([
        ('2000_change', Change('2000', '2001')),
        ('2001_change', Change('2001', '2002')),
        ('2002_change', Change('2002', '2003'))
    ])

Or, better yet, compute the whole decade using a loop:

.. code-block:: Python

    computations = []

    for year in range(2000, 2010):
        change = Change(year, year + 1)
        computations.append(('%i_change' % year, change))

    new_table = table.compute(computations)

Percent
=======

Calculate the percentage for each value in a column with :class:`.Percent`.
Values are divided into the sum of the column by default. 

.. code-block:: python

    columns = ('value',)
    rows = ([1],[2],[2],[5])
    new_table = agate.Table(rows, columns)

    new_table = new_table.compute([
        ('percent', agate.Percent('value'))
    ])

    new_table.print_table()

    |--------+----------|
    |  value | percent  |
    |--------+----------|
    |      1 |      10  |
    |      2 |      20  |
    |      2 |      20  |
    |      5 |      50  |
    |--------+----------|

Override the denominator with a keyword argument.

.. code-block:: python

    new_table = new_table.compute([
        ('percent', agate.Percent('value', 5))
    ])

    new_table.print_table()

    |--------+----------|
    |  value | percent  |
    |--------+----------|
    |      1 |      20  |
    |      2 |      40  |
    |      2 |      40  |
    |      5 |     100  |
    |--------+----------|

Percent change
==============
{'fraction_non_alphanumeric': 0.23060156931124673, 'fraction_numerical': 0.05231037489102005, 'mean_word_length': 2.0681818181818183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1173670', 'n_tokens_mistral': 780, 'n_tokens_neox': 669, 'n_words': 176}