Skip to content

Commit

Permalink
Cookbook: standardize names and values. Closes wireservice#612 closes w…
Browse files Browse the repository at this point in the history
  • Loading branch information
nbedi committed Jul 29, 2016
1 parent a6c03f0 commit 268967d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Welcome to the agate cookbook, a source of how-to's and use cases.
cookbook/filter
cookbook/sort
cookbook/search
cookbook/standardize
cookbook/statistics
cookbook/compute
cookbook/datetime
Expand All @@ -38,6 +39,7 @@ Basics
* `Filtering rows of data <cookbook/filter.html>`_
* `Sorting rows of data <cookbook/sort.html>`_
* `Searching through a table <cookbook/search.html>`_
* `Standardize names and values <cookbook/standardize.html>`_
* `Calculating statistics <cookbook/statistics.html>`_
* `Computing new columns <cookbook/compute.html>`_
* `Handling dates and times <cookbook/datetime.html>`_
Expand Down
40 changes: 40 additions & 0 deletions docs/cookbook/standardize.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,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))
])

0 comments on commit 268967d

Please sign in to comment.