unique¶
- astropy.table.unique(input_table, keys=None, silent=False, keep='first')[source]¶
Returns the unique rows of a table.
- Parameters:
- input_tableastropy:table-like
- keys
python:str
orpython:list
ofpython:str
Name(s) of column(s) used to create unique rows. Default is to use all columns.
- keep{‘first’, ‘last’, ‘none’}
Whether to keep the first or last row for each set of duplicates. If ‘none’, all rows that are duplicate are removed, leaving only rows that are already unique in the input. Default is ‘first’.
- silentbool
If
True
, masked value column(s) are silently removed fromkeys
. IfFalse
, an exception is raised whenkeys
contains masked value column(s). Default isFalse
.
- Returns:
- unique_table
Table
object
New table containing only the unique rows of
input_table
.
- unique_table
Examples
>>> from astropy.table import unique, Table >>> import numpy as np >>> table = Table(data=[[1,2,3,2,3,3], ... [2,3,4,5,4,6], ... [3,4,5,6,7,8]], ... names=['col1', 'col2', 'col3'], ... dtype=[np.int32, np.int32, np.int32]) >>> table <Table length=6> col1 col2 col3 int32 int32 int32 ----- ----- ----- 1 2 3 2 3 4 3 4 5 2 5 6 3 4 7 3 6 8 >>> unique(table, keys='col1') <Table length=3> col1 col2 col3 int32 int32 int32 ----- ----- ----- 1 2 3 2 3 4 3 4 5 >>> unique(table, keys=['col1'], keep='last') <Table length=3> col1 col2 col3 int32 int32 int32 ----- ----- ----- 1 2 3 2 5 6 3 6 8 >>> unique(table, keys=['col1', 'col2']) <Table length=5> col1 col2 col3 int32 int32 int32 ----- ----- ----- 1 2 3 2 3 4 2 5 6 3 4 5 3 6 8 >>> unique(table, keys=['col1', 'col2'], keep='none') <Table length=4> col1 col2 col3 int32 int32 int32 ----- ----- ----- 1 2 3 2 3 4 2 5 6 3 6 8 >>> unique(table, keys=['col1'], keep='none') <Table length=1> col1 col2 col3 int32 int32 int32 ----- ----- ----- 1 2 3