File: columns.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 (24 lines) | stat: -rw-r--r-- 835 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
===============================
Renaming and reordering columns
===============================

Rename columns
===============

You can rename the columns in a table by using the :meth:`.Table.rename` method and specifying the new column names as an array or dictionary mapping old column names to new ones.

.. code-block:: python

    table = Table(rows, column_names = ['a', 'b', 'c'])
    new_table = table.rename(column_names = ['one', 'two', 'three'])
    # or
    new_table = table.rename(column_names = {'a': 'one', 'b': 'two', 'c': 'three'})

Reorder columns
===============

You can reorder the columns in a table by using the :meth:`.Table.select` method and specifying the column names in the order you want:

.. code-block:: python

    new_table = table.select(['3rd_column_name', '1st_column_name', '2nd_column_name'])