File: standardize.rst

package info (click to toggle)
python-agate 1.13.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,008 kB
  • sloc: python: 8,578; makefile: 126
file content (40 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
============================
Standardize names and values
============================

Standardize row and columns names
=================================

The :meth:`Table.rename` method has arguments to convert row or column names to slugs and append unique identifiers to duplicate values.

Using an existing table object:

.. code-block:: python

    # Convert column names to unique slugs
    table.rename(slug_columns=True)

    # Convert row names to unique slugs
    table.rename(slug_rows=True)

    # Convert both column and row names to unique slugs
    table.rename(slug_columns=True, slug_rows=True)

Standardize column values
=========================

agate has a :class:`Slug` computation that can be used to also standardize text column values. The computation has an option to also append unique identifiers to duplicate values.

Using an existing table object:

.. code-block:: python

    # Convert the values in column 'title' to slugs
    new_table = table.compute([
        ('title-slug', agate.Slug('title'))
    ])
    
    # Convert the values in column 'title' to unique slugs
    new_table = table.compute([
        ('title-slug', agate.Slug('title', ensure_unique=True))
    ])