Skip to content

Table(*arguments, **keyword_arguments) Source

Named columns, each holding values of one type, wrapping a pandas DataFrame.

A Table never changes: every operation returns a new Table. Its rows are numbered from 0, and renumbered after a filter or a sort. Integer, boolean and text columns accept missing values.

Calling ndp.Table(...), comparisons, brackets, for, in, len and bool are refused with RefusedOperationError, which names the method to use instead.

Added in version 0.1.0

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Paris"])
prices = ndp.Array.from_list([120.0, 80.0, 150.0])
sales = ndp.Table.from_arrays({"city": cities, "price": prices})
sales
#     city   price
#     TEXT FLOAT64
# 0  Paris   120.0
# 1   Lyon    80.0
# 2  Paris   150.0
sales.row_count
# 3
sales.column_names
# ['city', 'price']

Reading files

from_csv(path, options=None) Source

Return a Table read from a CSV file whose first row holds the column names.

Each column takes the type of all its values, even in a long file: a column mixing numbers and texts is read as texts written as in the file, such as 01.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.csv" or Path("data/sales.csv").

  • options (CsvReadOptions | None, default: None)

    The separator and the encoding, "," and UTF-8 when omitted.

Returns:

  • Self

    A new Table, empty for an empty file.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.csv"
_ = path.write_text("city;price\nParis;1.5\nLyon;\n")
ndp.Table.from_csv(path, ndp.CsvReadOptions(separator=";"))
#     city   price
#     TEXT FLOAT64
# 0  Paris     1.5
# 1   Lyon     NaN

from_json(path, options=None) Source

Return a Table read from a JSON file in UTF-8 holding one object per row.

Each column takes the type of its JSON values: a text that looks like a number or a date stays a text.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.json" or Path("data/sales.json").

  • options (JsonReadOptions | None, default: None)

    The layout of the rows, one list of objects when omitted.

Returns:

  • Self

    A new Table, with one column per name found in the objects.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.jsonl"
_ = path.write_text('{"city": "Paris", "count": 2}\n{"city": "Lyon", "count": null}\n')
ndp.Table.from_json(path, ndp.JsonReadOptions(layout=ndp.JsonLayout.LINES))
#     city count
#     TEXT INT64
# 0  Paris     2
# 1   Lyon  <NA>

from_excel(path, options=None) Source

Return a Table read from a sheet of an Excel file whose first row holds the column names.

Needs the excel extra: pip install numdaplot[excel].

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.xlsx" or Path("data/sales.xlsx").

  • options (ExcelReadOptions | None, default: None)

    The sheet to read, the first one when omitted.

Returns:

  • Self

    A new Table. Dates of the sheet become DATETIME columns. A column of time cells only, such as hh:mm, becomes TIME, and a column of duration cells only, such as [h]:mm, DURATION: a column mixing them with texts stays TEXT.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.xlsx"
ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5])}).to_excel(path)
ndp.Table.from_excel(path).column_types
# {'price': <Type.FLOAT64: 10>}

from_parquet(path, options=None) Source

Return a Table read from a Parquet file.

Needs the parquet extra: pip install numdaplot[parquet].

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.parquet" or Path("data/sales.parquet").

  • options (ParquetReadOptions | None, default: None)

    Whether the column names are cleaned, cleaned when omitted.

Returns:

  • Self

    A new Table, with the types stored in the file.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.parquet"
ndp.Table.from_arrays({"count": ndp.Array.from_list([3])}).to_parquet(path)
ndp.Table.from_parquet(path).column_types
# {'count': <Type.INT64: 4>}

from_stata(path, options=None) Source

Return a Table read from a Stata file (.dta).

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.dta" or Path("data/sales.dta").

  • options (StataReadOptions | None, default: None)

    Whether the column names are cleaned, cleaned when omitted.

Returns:

  • Self

    A new Table, with the types stored in the file.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.dta"
ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5])}).to_stata(path)
ndp.Table.from_stata(path).column_types
# {'price': <Type.FLOAT64: 10>}

from_sas(path, options=None) Source

Return a Table read from a SAS data file (.sas7bdat). numdaplot does not write this format.

The example reads airline.sas7bdat, a SAS data file of 32 rows.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.sas7bdat" or Path("data/sales.sas7bdat").

  • options (SasReadOptions | None, default: None)

    The encoding of the texts, UTF-8 when omitted.

Returns:

  • Self

    A new Table. SAS stores every number as a decimal, so numbers become FLOAT64.

Raises:

Examples:

import numdaplot as ndp

airline = ndp.Table.from_sas("airline.sas7bdat")
airline.preview(ndp.Preview(count=3))
#      YEAR       Y       W       R       L       K
#   FLOAT64 FLOAT64 FLOAT64 FLOAT64 FLOAT64 FLOAT64
# 0  1948.0   1.214   0.243  0.1454   1.415   0.612
# 1  1949.0   1.354   0.260  0.2181   1.384   0.559
# 2  1950.0   1.569   0.278  0.3157   1.388   0.573

from_xpt(path, options=None) Source

Return a Table read from a SAS transport file (.xpt). numdaplot does not write this format.

The example reads paxraw_d_short.xpt, a SAS transport file of 100 rows.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.xpt" or Path("data/sales.xpt").

  • options (XptReadOptions | None, default: None)

    The encoding of the texts, UTF-8 when omitted.

Returns:

  • Self

    A new Table. SAS stores every number as a decimal, so numbers become FLOAT64.

Raises:

Examples:

import numdaplot as ndp

activity = ndp.Table.from_xpt("paxraw_d_short.xpt")
activity.row_count
# 100
activity.column_names
# ['SEQN', 'PAXSTAT', 'PAXCAL', 'PAXDAY', 'PAXN', 'PAXHOUR', 'PAXMINUT', 'PAXINTEN', 'PAXSTEP']

Writing files

to_csv(path, options=None, on_conflict=Conflict.ERROR) Source

Write the Table in a CSV file, column names on the first row, without row numbers.

Missing values are written as empty values, and times of day as texts such as 15:35:00.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.csv" or Path("data/sales.csv").

  • options (CsvWriteOptions | None, default: None)

    The separator and the encoding, "," and UTF-8 when omitted.

  • on_conflict (Conflict, default: Conflict.ERROR)

    ERROR by default, refusing to overwrite an existing file, or REPLACE to overwrite it.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • FileExistsError

    When a file exists at the path and on_conflict is ERROR.

  • FileAccessError

    When the file system refuses the file: missing folder, missing permission and so on.

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.csv"
table = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])})
table.to_csv(path, ndp.CsvWriteOptions(separator=";"))
print(path.read_text())
# price
# 1.5
# 8.0
#

to_json(path, options=None, on_conflict=Conflict.ERROR) Source

Write the Table in a JSON file in UTF-8, one object per row.

Missing values are written as null, dates and durations in the ISO 8601 format, times of day as texts such as 15:35:00, and decimals with every digit of their value unless options gives their number.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.json" or Path("data/sales.json").

  • options (JsonWriteOptions | None, default: None)

    The layout of the rows and the number of decimals, one list of objects with every digit when omitted.

  • on_conflict (Conflict, default: Conflict.ERROR)

    ERROR by default, refusing to overwrite an existing file, or REPLACE to overwrite it.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • FileExistsError

    When a file exists at the path and on_conflict is ERROR.

  • FileAccessError

    When the file system refuses the file: missing folder, missing permission and so on.

  • ValueConversionError

    At the first infinite value of a decimal column, which JSON cannot write: replace it first.

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.json"
ndp.Table.from_arrays({"city": ndp.Array.from_list(["Paris"])}).to_json(path)
path.read_text()
# '[{"city":"Paris"}]'

to_excel(path, options=None, on_conflict=Conflict.ERROR) Source

Write the Table in a sheet of an Excel file, column names on the first row.

Times of day are written as texts such as 15:35:00. Needs the excel extra: pip install numdaplot[excel].

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.xlsx" or Path("data/sales.xlsx").

  • options (ExcelWriteOptions | None, default: None)

    The name of the sheet, "Sheet1" when omitted.

  • on_conflict (Conflict, default: Conflict.ERROR)

    ERROR by default, refusing to overwrite an existing file, or REPLACE to overwrite it.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.xlsx"
table = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5])})
table.to_excel(path, ndp.ExcelWriteOptions(sheet="Sales"))
ndp.Table.from_excel(path, ndp.ExcelReadOptions(sheet="Sales")).row_count
# 1

to_parquet(path, on_conflict=Conflict.ERROR) Source

Write the Table in a Parquet file, which keeps the type of each column.

Times of day are stored as Parquet times, read back as TIME. Needs the parquet extra: pip install numdaplot[parquet].

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.parquet" or Path("data/sales.parquet").

  • on_conflict (Conflict, default: Conflict.ERROR)

    ERROR by default, refusing to overwrite an existing file, or REPLACE to overwrite it.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.parquet"
ndp.Table.from_arrays({"count": ndp.Array.from_list([3])}).to_parquet(path)
path.exists()
# True

to_stata(path, on_conflict=Conflict.ERROR) Source

Write the Table in a Stata file (.dta).

Stata stores integers and booleans holding missing values as decimals, a missing text as an empty text, and times of day as texts such as 15:35:00, as it has no type for them. Column names that Stata refuses, such as names with spaces, are changed by pandas with a warning.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the file, a FilePath such as "sales.dta" or Path("data/sales.dta").

  • on_conflict (Conflict, default: Conflict.ERROR)

    ERROR by default, refusing to overwrite an existing file, or REPLACE to overwrite it.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • FileExistsError

    When a file exists at the path and on_conflict is ERROR.

  • FileAccessError

    When the file system refuses the file: missing folder, missing permission and so on.

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "sales.dta"
ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5])}).to_stata(path)
path.exists()
# True

Information

shape: Shape Source

Number of rows, then number of columns.

Added in version 0.2.0

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Pau", "Lyon", "Nice"])
prices = ndp.Array.from_list([1.5, 8.0, 3.0])
ndp.Table.from_arrays({"city": cities, "price": prices}).shape
# Shape(dimensions=[3, 2])

row_count: int Source

Number of rows.

Added in version 0.1.0

Examples:

import numdaplot as ndp

ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])}).row_count
# 2

column_count: int Source

Number of columns.

Added in version 0.1.0

Examples:

import numdaplot as ndp

ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])}).column_count
# 1

column_names: list[str] Source

Names of the columns, in order. Changing the returned list never changes the Table.

Added in version 0.1.0

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris"])
prices = ndp.Array.from_list([1.5])
ndp.Table.from_arrays({"city": cities, "price": prices}).column_names
# ['city', 'price']

column_types: dict[str, Type] Source

Type of each column, by column name, in the order of the columns.

Added in version 0.1.0

Examples:

import numdaplot as ndp

ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5])}).column_types
# {'price': <Type.FLOAT64: 10>}

column_time_zones: dict[str, TimeZone | None] Source

Time zone of each datetime column, by column name, None for a datetime column without zone.

Columns of other types are not listed.

Added in version 0.1.0

Examples:

from datetime import datetime
import numdaplot as ndp

times = ndp.Table.from_arrays({"time": ndp.Array.from_list([datetime(2026, 7, 1, 10, 30)])})
times.column_time_zones
# {'time': None}

Conversion and comparison

from_pandas(frame, column_names=ColumnNames.CLEANED) Source

Return a Table holding a copy of a pandas DataFrame; changing the DataFrame never changes the Table.

Added in version 0.1.0

Parameters:

  • frame (pandas.DataFrame)

    A pandas DataFrame whose index is the row numbers 0, 1, 2... Python objects become dates, datetimes, durations, times of day, integers, decimals or booleans when they all are, and texts otherwise. Durations of any unit become DURATION, and datetime.time objects TIME.

  • column_names (ColumnNames, default: ColumnNames.CLEANED)

    Whether the column names are cleaned, ColumnNames.CLEANED by default: the spaces, tabs and line breaks at the start and the end of each name are removed. ColumnNames.KEPT keeps the names as written.

Returns:

  • Self

    A new Table.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • UnsupportedIndexError

    When the index holds other values: call reset_index() first to keep them as a column.

  • (InvalidColumnNameError, DuplicateColumnError)

    When a column name is not a non-empty text, even once cleaned, or appears twice, or two names become the same once cleaned.

  • UnsupportedTypeError

    When a column has a type numdaplot does not support, such as complex numbers or datetimes with a time zone.

  • TimeOverflowError

    When a column holds a datetime outside 1677 to 2262, or a duration beyond about 292 years.

Examples:

import pandas
import numdaplot as ndp

ndp.Table.from_pandas(pandas.DataFrame({"city": ["Pau", None], "count": [2, 3]}))
#    city count
#    TEXT INT64
# 0   Pau     2
# 1  <NA>     3

from_arrays(columns) Source

Return a Table whose columns hold the values of one-dimensional Arrays.

Added in version 0.1.0

Parameters:

  • columns (dict[str, Array])

    One Array per column, by column name, all of the same length.

Returns:

  • Self

    A new Table, columns in the order of the dictionary.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon"])
prices = ndp.Array.from_list([1.5, 8.0])
ndp.Table.from_arrays({"city": cities, "price": prices})
#     city   price
#     TEXT FLOAT64
# 0  Paris     1.5
# 1   Lyon     8.0

to_pandas() Source

Return a pandas copy of the Table; changing it never changes the Table.

Integers, booleans and texts use the pandas dtypes that accept missing values (pd.NA).

Added in version 0.1.0

Returns:

  • pandas.DataFrame

    A copy, rows numbered from 0. Times of day are datetime.time objects, as pandas has no type for them.

Examples:

import numdaplot as ndp

ndp.Table.from_arrays({"count": ndp.Array.from_list([2, 3])}).to_pandas().dtypes.tolist()
# [Int64Dtype()]

column(column_name) Source

Return the values of a column as an Array.

Added in version 0.1.0

Parameters:

  • column_name (str)

    The name of the column.

Returns:

  • Array

    A one-dimensional Array of the type of the column, with the same number of values as the Table has rows; a CATEGORY column gives a TEXT Array.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])})
table.column("price").compute(ndp.Sum()).to_value()
# 9.5

to_value() Source

Return the single value of a Table of one row and one column, as a Python value.

Added in version 0.1.0

Returns:

  • Any

    The value, None when it is missing. A datetime with a time zone keeps its zone.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5, 8.0])})
highest_price = ndp.Calculation(column="price", function=ndp.Max())
table.aggregate(ndp.Aggregation(calculations=[highest_price])).to_value()
# 8.0

is_equal(equality) Source

Return whether this Table and another one have the same columns, in the same order, with the same values.

Two missing values at the same row are equal. Datetime columns in different time zones are different, even for the same instants.

Added in version 0.1.0

Parameters:

  • equality (Equality)

    The other Table, and whether the type of each column must also be the same.

Returns:

  • bool

    True when both Tables are equal.

Raises:

Examples:

import numdaplot as ndp

integers = ndp.Table.from_arrays({"count": ndp.Array.from_list([1, 2])})
decimals = ndp.Table.from_arrays({"count": ndp.Array.from_list([1.0, 2.0])})
integers.is_equal(ndp.Equality(other=decimals))
# True

Selection

filter(row_filter) Source

Return the rows satisfying a filter.

Added in version 0.1.0

Parameters:

  • row_filter (Filter)

    The conditions and how they combine. A missing value only satisfies IsMissing.

Returns:

  • Self

    A new Table with the kept rows, in their order, numbered from 0.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Pau"])
prices = ndp.Array.from_list([120.0, 80.0, 150.0])
table = ndp.Table.from_arrays({"city": cities, "price": prices})
expensive = ndp.Condition(rule=ndp.Greater(100), columns=["price"])
table.filter(ndp.Filter(conditions=[expensive]))
#     city   price
#     TEXT FLOAT64
# 0  Paris   120.0
# 1    Pau   150.0

take(region) Source

Return the rows and the columns of a region.

A row chosen with Index gives a Table of one row. Use to_value to read a single value.

Added in version 0.1.0

Parameters:

  • region (Region)

    The rows and the columns, every one of a dimension when omitted. Columns are positions or names; negative positions count from the end.

Returns:

  • Self

    A new Table, rows numbered from 0, columns in the order of the region.

Raises:

Examples:

import numdaplot as ndp

prices = ndp.Array.from_list([120.0, 80.0, 150.0])
table = ndp.Table.from_arrays({"price": prices})
table.take(ndp.Region(rows=ndp.Range(start=1, stop=2), columns=["price"]))
#     price
#   FLOAT64
# 0    80.0
# 1   150.0

check(rule) Source

Return which values satisfy a rule, in every column.

To check some columns only, choose them first with choose_columns.

Added in version 0.1.0

Parameters:

Returns:

  • Self

    A new Table with the same columns and rows, holding True where the value satisfies the rule. Every column is of type BOOL.

Raises:

Examples:

import numdaplot as ndp

prices = ndp.Array.from_list([120.0, None, 150.0])
stocks = ndp.Array.from_list([3.0, 5.0, None])
table = ndp.Table.from_arrays({"price": prices, "stock": stocks})
table.check(ndp.IsMissing())
#    price  stock
#     BOOL   BOOL
# 0  False  False
# 1   True  False
# 2  False   True

Columns

choose_columns(choice) Source

Return the Table with only some columns, or without some columns.

Added in version 0.1.0

Parameters:

  • choice (ColumnChoice)

    The columns, and whether to keep them, in the order of the list, or to drop them.

Returns:

  • Self

    A new Table.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris"])
prices = ndp.Array.from_list([1.5])
table = ndp.Table.from_arrays({"city": cities, "price": prices})
table.choose_columns(ndp.ColumnChoice(columns=["city"], mode=ndp.ColumnMode.DROP)).column_names
# ['price']

rename(renaming) Source

Return the Table with renamed columns, every renaming applied at once.

Two columns can swap their names in a single call.

Added in version 0.1.0

Parameters:

Returns:

  • Self

    A new Table, columns in the same order.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"prix": ndp.Array.from_list([1.5])})
table.rename(ndp.Renaming(changes=[ndp.NameChange(old_name="prix", new_name="price")])).column_names
# ['price']

convert(conversion) Source

Return the Table with columns converted to another type, missing values staying missing.

Changed in version 0.2.0

Converts every column of TableConversion.columns.

Version history (1)

Added in version 0.1.0

Parameters:

  • conversion (TableConversion)

    The columns, their new type, and the date format or the time zone change. Accepted: between number types, from numbers, booleans, categories, dates, datetimes and durations to texts, from texts and categories to numbers, booleans ("true" or "false" in any case), dates or datetimes, from any other type to categories, between dates and datetimes, and a time zone change of datetimes.

Returns:

  • Self

    A new Table, each column at its place.

Raises:

Examples:

import numdaplot as ndp

zip_codes = ndp.Array.from_list(["06000", "75001"])
department_codes = ndp.Array.from_list(["06", "75"])
places = ndp.Table.from_arrays({"zip_code": zip_codes, "department": department_codes})
places.convert(ndp.TableConversion(columns=["zip_code", "department"], dtype=ndp.Type.INT32))
#   zip_code department
#      INT32      INT32
# 0     6000          6
# 1    75001         75

apply(application) Source

Return the Table with a math function, a time function or a value mapping applied to each value of columns.

Unlike Array.apply, an integer or boolean column keeps its type when a ValueMapping gives it missing values, since a Table column can hold them.

Added in version 0.2.0

Parameters:

Returns:

  • Self

    A new Table, each column replaced at its place, under its name. Missing values stay missing.

Raises:

Warns:

Examples:

import numdaplot as ndp

first_answers = ndp.Array.from_list([1, 7, 2])
second_answers = ndp.Array.from_list([9, 3, 1])
survey = ndp.Table.from_arrays({"q1": first_answers, "q2": second_answers})
unknown_answers = [ndp.ValueChange(7, None), ndp.ValueChange(9, None)]
mapping = ndp.ValueMapping(changes=unknown_answers, others=ndp.Unmatched.KEEP)
survey.apply(ndp.TableApplication(function=mapping, columns=["q1", "q2"]))
#      q1    q2
#   INT64 INT64
# 0     1  <NA>
# 1  <NA>     3
# 2     2     1

add_column(new_column) Source

Return the Table with one more column, or with a column replaced.

Added in version 0.1.0

Parameters:

  • new_column (NewColumn)

    The name, a one-dimensional Array with one value per row, and what to do when the name exists.

Returns:

  • Self

    A new Table. A new column is placed last; a replaced column keeps its place.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"price": ndp.Array.from_list([10.0, 20.0])})
taxed_prices = table.column("price") * 1.2
table.add_column(ndp.NewColumn(name="taxed_price", values=taxed_prices))
#     price taxed_price
#   FLOAT64     FLOAT64
# 0    10.0        12.0
# 1    20.0        24.0

Calculation

aggregate(aggregation) Source

Return statistics of the whole Table, or of each group of rows.

Added in version 0.1.0

Changed in version 0.2.0

Gives the number of rows of each group with the row_count of the aggregation.

Parameters:

  • aggregation (Aggregation)

    The calculations, the columns forming the groups, and the name of the row count column.

Returns:

  • Self

    A new Table: the group columns, then the row_count column, then one column per calculation; one row per group, sorted by group values with missing values as a group of their own, last. Without groups, a single row. A statistic needing a value gives a missing value for a group without present value.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Pau", "Lyon", "Pau"])
prices = ndp.Array.from_list([10.0, 30.0, 20.0])
table = ndp.Table.from_arrays({"city": cities, "price": prices})
average_price = ndp.Calculation(column="price", function=ndp.Mean())
table.aggregate(ndp.Aggregation(calculations=[average_price], group_by=["city"]))
#    city price_mean
#    TEXT    FLOAT64
# 0  Lyon       30.0
# 1   Pau       15.0

pivot_table(pivot) Source

Return one statistic for each combination of groups of rows and values of a column, as a wide Table.

aggregate gives one row per combination: pivot_table gives one column per value of a column, as Plot.heatmap draws them.

Added in version 0.1.0

Parameters:

  • pivot (PivotTable)

    The columns forming the rows and the columns of the result, and the statistic of each cell.

Returns:

  • Self

    A new Table: the columns of rows, then one column per value of columns, named after the value; one row per group, sorted, with missing values as a group of their own, last.

Raises:

Examples:

import numdaplot as ndp

hours = ndp.Array.from_list([8, 8, 9])
weekdays = ndp.Array.from_list(["Mon", "Tue", "Mon"])
fares = ndp.Array.from_list([7.0, 9.0, 5.0])
trips = ndp.Table.from_arrays({"hour": hours, "weekday": weekdays, "fare": fares})
trip_count = ndp.Calculation(column="fare", function=ndp.Count(missing=ndp.CountedMissing.INCLUDED))
trips.pivot_table(ndp.PivotTable(rows=["hour"], columns="weekday", calculation=trip_count))
#    hour   Mon   Tue
#   INT64 INT64 INT64
# 0     8     1     1
# 1     9     1     0

describe(description=None) Source

Return statistics describing columns, one row per statistic and one column per described column.

Added in version 0.1.0

Parameters:

  • description (Description | None, default: None)

    The statistics and the columns. When omitted, every number column is described with the statistics of pandas.

Returns:

  • Self

    A new Table whose first column, statistic, names each statistic, such as quantile_25. A cell is missing when the statistic does not apply to the column or finds no value.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"price": ndp.Array.from_list([10.0, 30.0])})
table.describe(ndp.Description(functions=[ndp.Count(), ndp.Mean(), ndp.Max()]))
#         statistic   price
#              TEXT FLOAT64
# 0  count_excluded     2.0
# 1            mean    20.0
# 2             max    30.0

count_values(value_count) Source

Return how many rows hold each value of a column, as a number or as a fraction of every row.

With weights, each row counts as much as its weight, such as the people of a population a survey answer stands for.

Added in version 0.2.0

Parameters:

  • value_count (ValueCount)

    The counted column, the measure, a number of rows by default, and the column of weights.

Returns:

  • Self

    A new Table: the counted column holding each value once, then value_count, or value_ratio for Measure.RATIO, or with weights weighted_count or weighted_ratio. Rows go from the most frequent value to the least frequent, values with the same count sorted by value. The missing value has a row of its own, last, so the ratios add up to 1.

Raises:

Examples:

import numdaplot as ndp

answers = ndp.Table.from_arrays({"sex": ndp.Array.from_list([2.0, 1.0, 2.0, None, 2.0, 1.0])})
answers.count_values(ndp.ValueCount(column="sex"))
#       sex value_count
#   FLOAT64       INT64
# 0     2.0           3
# 1     1.0           2
# 2     NaN           1
answers.count_values(ndp.ValueCount(column="sex", measure=ndp.Measure.RATIO))
#       sex value_ratio
#   FLOAT64     FLOAT64
# 0     2.0    0.500000
# 1     1.0    0.333333
# 2     NaN    0.166667

Layout

sort(sorting) Source

Return the rows sorted by one or several columns.

Added in version 0.1.0

Parameters:

  • sorting (TableSorting)

    The sort keys, each with its order and the place of its missing values.

Returns:

  • Self

    A new Table, rows numbered from 0. Rows equal on every key keep their order.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"price": ndp.Array.from_list([20.0, 10.0, 30.0])})
table.sort(ndp.TableSorting(keys=[ndp.SortKey(column="price", order=ndp.Order.DESCENDING)]))
#     price
#   FLOAT64
# 0    30.0
# 1    20.0
# 2    10.0

drop_duplicates(deduplication=None) Source

Return the Table without its duplicated rows.

Added in version 0.1.0

Parameters:

  • deduplication (Deduplication | None, default: None)

    The compared columns, every column when omitted, and the row kept in each group. Two missing values are equal.

Returns:

  • Self

    A new Table, remaining rows in their order, numbered from 0.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"city": ndp.Array.from_list(["Pau", "Lyon", "Pau"])})
table.drop_duplicates()
#    city
#    TEXT
# 0   Pau
# 1  Lyon

Join

join(join) Source

Return the rows of this Table and of another Table put side by side where their keys match.

Added in version 0.1.0

Parameters:

  • join (Join)

    The other Table, the key columns, the rows kept, how the columns both Tables have are told apart, and how many times each key may appear.

Returns:

  • Self

    A new Table: the keys, then the other columns of this Table, then those of the other Table. The rows of this Table come first, in their order, each once per match, then the unmatched rows of the other Table kept by the mode. Missing values fill the columns of a Table that has no matching row, each column keeping its type.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • ColumnNotFoundError

    When a key is missing from one of the Tables.

  • IncompatibleTypesError

    When the two columns of a key are of different families, of different types with KeyTypes.SAME_TYPE, or a date and a datetime: convert one of them first.

  • TimeZoneMismatchError

    When the two columns of a key hold datetimes of different time zones, or with and without one: change them first with TimeZoneChange.

  • JoinRelationError

    When a key is repeated in a Table where the relation of the join expects it once.

  • DuplicateColumnError

    When both Tables have a column besides the keys and the join has no suffixes, or a suffixed name is already the name of another column.

Examples:

import numdaplot as ndp

accidents = ndp.Table.from_arrays(
    {"Num_Acc": ndp.Array.from_list([101, 102]), "dep": ndp.Array.from_list(["75", "69"])}
)
users = ndp.Table.from_arrays(
    {"Num_Acc": ndp.Array.from_list([101, 101, 103]), "grav": ndp.Array.from_list([1, 3, 2])}
)
accidents.join(ndp.Join(other=users, keys=["Num_Acc"], mode=ndp.JoinMode.LEFT))
#   Num_Acc  dep  grav
#     INT64 TEXT INT64
# 0     101   75     1
# 1     101   75     3
# 2     102   69  <NA>

Missing values

count_missing(missing_count=None, axis=None) Source

Return the number or the ratio of missing values, for the whole Table, each row or each column.

Added in version 0.1.0

Parameters:

  • missing_count (MissingCount | None, default: None)

    The measure, the number of missing values when omitted.

  • axis (Axis | None, default: None)

    One count per row with Axis.EACH_ROW, one per column with Axis.EACH_COLUMN, a single count for the whole Table when omitted.

Returns:

  • Self

    A new Table with a missing_count column, or missing_ratio for Measure.RATIO: one row for the whole Table, read with to_value, one row per row, or one row per column after a column column naming it. A ratio is missing when there is no value to count.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Pau", "Nice"])
prices = ndp.Array.from_list([120.0, None, None, 90.0])
table = ndp.Table.from_arrays({"city": cities, "price": prices})
table.count_missing().to_value()
# 2
table.count_missing(ndp.MissingCount(measure=ndp.Measure.RATIO), axis=ndp.Axis.EACH_COLUMN)
#   column missing_ratio
#     TEXT       FLOAT64
# 0   city           0.0
# 1  price           0.5

preview_missing() Source

Show the number and the percentage of missing values of each column, then of the whole Table.

In a Jupyter notebook the summary is shown as an HTML table, elsewhere as text. Nothing is returned: use count_missing to compute with these numbers.

Added in version 0.1.0

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Pau"])
prices = ndp.Array.from_list([120.0, None, 150.0])
table = ndp.Table.from_arrays({"city": cities, "price": prices})
table.preview_missing()
#           column     type  missing_count missing_ratio
# 0           city     TEXT              0         0.0 %
# 1          price  FLOAT64              1        33.3 %
# 2  (all columns)                       1        16.7 %

drop_missing(missing_drop=None, axis=Axis.EACH_ROW) Source

Return the Table without its rows, or its columns, holding missing values.

Added in version 0.1.0

Parameters:

Returns:

  • Self

    A new Table, remaining rows in their order and numbered from 0, or remaining columns in their order.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Pau"])
prices = ndp.Array.from_list([120.0, None, 150.0])
table = ndp.Table.from_arrays({"city": cities, "price": prices})
table.drop_missing()
#     city   price
#     TEXT FLOAT64
# 0  Paris   120.0
# 1    Pau   150.0

Display

preview(preview=None) Source

Show a few rows, with their row numbers and the type of each column under its name.

In a Jupyter notebook the rows are shown as an HTML table, elsewhere as text. Every column is shown unless the settings ask for a compact display. Nothing is returned.

Added in version 0.1.0

Parameters:

  • preview (Preview | None, default: None)

    How many rows, which ones, and how the columns are shown: the first 5, with every column, when omitted.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"price": ndp.Array.from_list([10.0, 20.0, 30.0])})
table.preview(ndp.Preview(count=2, side=ndp.Side.END))
#     price
#   FLOAT64
# 1    20.0
# 2    30.0

__repr__() Source

Return the text of the Table, with the type of each column under its name.

A long Table only shows its first and last rows, as in pandas. Every column is shown, going on after a line break, ended by a backslash, when they do not fit in the width of the terminal.

Added in version 0.1.0

Returns:

  • str

    The text shown by print(table).

Examples:

import numdaplot as ndp

print(ndp.Table.from_arrays({"paid": ndp.Array.from_list([True, False])}))
#     paid
#     BOOL
# 0   True
# 1  False

Refused operations

__eq__(other) Source

Refuse table == other; use is_equal.

Added in version 0.1.0

Parameters:

  • other (object)

    Any value.

Raises:

__ne__(other) Source

Refuse table != other; use is_equal.

Added in version 0.1.0

Parameters:

  • other (object)

    Any value.

Raises:

__lt__(other) Source

Refuse table < other; use filter.

Added in version 0.1.0

Parameters:

  • other (object)

    Any value.

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"price": ndp.Array.from_list([1.5])})
try:
    table < 2
except ndp.RefusedOperationError as error:
    print(error)
# Comparing a Table with < is not available, use filter with a rule such as ndp.Greater instead.

__le__(other) Source

Refuse table <= other; use filter.

Added in version 0.1.0

Parameters:

  • other (object)

    Any value.

Raises:

__gt__(other) Source

Refuse table > other; use filter.

Added in version 0.1.0

Parameters:

  • other (object)

    Any value.

Raises:

__ge__(other) Source

Refuse table >= other; use filter.

Added in version 0.1.0

Parameters:

  • other (object)

    Any value.

Raises:

__getitem__(key) Source

Refuse table[...]; use column, take or filter.

Added in version 0.1.0

Parameters:

  • key (object)

    Any value.

Raises:

__setitem__(key, value) Source

Refuse table[...] = value; use add_column, which returns a new Table.

Added in version 0.1.0

Parameters:

  • key (object)

    Any value.

  • value (object)

    Any value.

Raises:

__iter__() Source

Refuse for row in table; iterate over the values of a column instead.

Added in version 0.1.0

Raises:

Examples:

import numdaplot as ndp

table = ndp.Table.from_arrays({"city": ndp.Array.from_list(["Paris", "Lyon"])})
for city in table.column("city").to_list():
    print(city)
# Paris
# Lyon

__contains__(value) Source

Refuse value in table; use filter with ndp.Equal or ndp.IsIn, or column_names.

Added in version 0.1.0

Parameters:

  • value (object)

    Any value.

Raises:

__len__() Source

Refuse len(table); read the row_count attribute instead.

Added in version 0.1.0

Raises:

__bool__() Source

Refuse if table: and bool(table), whose meaning would be unclear.

Added in version 0.1.0

Raises: