iode.Tables.__getitem__
- Tables.__getitem__(key: str | List[str]) Table | Self[source]
Return the (subset of) table(s) referenced by key.
The key can represent a single object name (e.g. “ACAF”) or a list of object names (“ACAF;ACAG;AOUC”) or a pattern (e.g. “A*”) or a list of sub-patterns (e.g. “A*;*_”).
If the key represents a list of object names or of sub-patterns, each name or sub-pattern is separated by a separator character which is either a whitespace ` , or a comma `,, or a semi-colon ;, or a tabulation t, or a newline n.
A (sub-)`pattern` is a list of characters representing a group of object names. It includes some special characters which have a special meaning:
* : any character sequence, even empty
? : any character (one and only one)
@ : any alphanumerical char [A-Za-z0-9]
& : any non alphanumerical char
| : any alphanumeric character or none at the beginning and end of a string
! : any non-alphanumeric character or none at the beginning and end of a string
`` : escape the next character
Note that the key can contain references to IODE lists which are prefixed with the symbol $.
- Parameters:
- key: str or list(str)
(the list of) name(s) of the table(s) to get. The list of tables to get can be specified by a pattern or by a list of sub-patterns (e.g. “A*;*_”).
- Returns:
- Single table or a subset of the database.
Examples
>>> from iode import SAMPLE_DATA_DIR >>> from iode import tables >>> tables.load(f"{SAMPLE_DATA_DIR}/fun.tbl") Loading .../fun.tbl 46 objects loaded
>>> # a) get one table >>> tables["YDH"] DIVIS | 1 | PC_*40.34 TITLE | "Tableau B-3. Revenu disponible des ménages à prix constant" ----- | --------------------------------------------------------------------------------------------------------- CELL | | "#S" CELL | "Revenus primaires" | WBU_+YN+GOSH_+IDH CELL | " Masse salariale totale" | WBU_ CELL | " Revenu net du travail en provenance du Reste du monde" | YN CELL | " Surplus brut d'exploitation" | GOSH_ CELL | " Revenu net de la propriété" | IDH CELL | "Cotisations sociales et impôts" | SSF+SSH+DTH CELL | " Cotisations patronales" | SSF CELL | " Cotisations personnelles" | SSH CELL | "IPP" | DTH CELL | "Prestations sociales " | SBH+OCUH CELL | " Sécurité sociale" | SBH CELL | " Diverses prestations" | OCUH CELL | "Total" | (WBU_+YN+GOSH_+IDH)-(SSF+SSH+DTH)+(SBH+OCUH) ----- | --------------------------------------------------------------------------------------------------------- FILES | DATE | nb lines: 19 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT'
>>> # b) get a subset of the Tables database using a pattern >>> tables_subset = tables["C8_*"] >>> tables_subset.names ['C8_1', 'C8_10', 'C8_11', 'C8_13', 'C8_14', 'C8_2', 'C8_3', 'C8_4', 'C8_5', 'C8_6', 'C8_7', 'C8_8', 'C8_9']
>>> # c) get a subset of the Tables database using a list of names >>> tables_subset = tables[["C8_1", "C8_2", "C8_4", "C8_5", "C8_7"]] >>> tables_subset.names ['C8_1', 'C8_2', 'C8_4', 'C8_5', 'C8_7']