lontras

class lontras.Array(initlist=None)

Bases: UserList

abs() Array

Returns the absolute values for Array

Returns:

Array: Absolute values Array

all() bool

Returns True if all values in the Array are truthy.

Returns:

bool: True if all values are truthy, False otherwise.

any() bool

Returns True if any value in the Array is True.

Returns:

bool: True if any value is True, False otherwise.

append(value: int | float | complex | str | bytes | bool) Array

Appends value to the end of the Array

Args:

value (Scalar): The data to append

Returns:

Array: A new Array with new data

argmax() int

Returns the index of the maximum value.

Returns:

int: The index of the maximum value.

argmin() int

Returns the index of the minimum value.

Returns:

int: The index of the minimum value.

copy(*, deep: bool = True)

Creates a copy of the Array.

Args:

deep (bool, optional): If True, creates a deep copy. Otherwise, creates a shallow copy. Defaults to True.

Returns:

Array: A copy of the Array.

dot(other: Array | Collection) int | float | complex | str | bytes | bool

Performs dot product with another Array, ArrayLike or Scalar.

If other is a Array or a ArrayLike, performs the dot product between the two. If other is a Scalar, multiplies all elements of the Array by the scalar and returns the sum.

Args:

other (Array | ArrayLike | Scalar)

Returns:

Scalar: The dot product of the Array.

classmethod full(size: int, fill_value: int | float | complex | str | bytes | bool) Array
map(func: Callable[[int | float | complex | str | bytes | bool], int | float | complex | str | bytes | bool]) Array

Applies a function to each value in the Array.

Args:

func (Callable[Scalar, Any]): The function to apply.

Returns:

Array: A new Array with the results of the function applied.

max() int | float | complex | str | bytes | bool

Returns the maximum value in the Array.

Returns:

Any: The maximum value.

min() int | float | complex | str | bytes | bool

Returns the minimum value in the Array.

Returns:

Any: The minimum value.

classmethod ones(size: int) Array
reduce(func: Callable[[Any, int | float | complex | str | bytes | bool], Any], initial: Any) Any

Reduces the Array using a function.

Args:

func (Callable[[Any, Scalar], Any]): The function to apply for reduction. initial (Any): The initial value for the reduction.

Returns:

Any: The reduced value.

sum() int | float | complex | str | bytes | bool

Returns the sum of the values in the Array.

Returns:

Any: The sum of the values.

to_list() list[Any]

Converts the Array to a list.

Returns:

list[Any]: A list of the Array values.

classmethod zeros(size: int) Array
class lontras.DataFrame(data: Mapping[int | float | complex | str | bytes | bool, Series] | Mapping[int | float | complex | str | bytes | bool, Collection] | Collection | Iterator | None = None, index: Sequence[int | float | complex | str | bytes | bool] | None = None, columns: Sequence[int | float | complex | str | bytes | bool] | None = None)

Bases: object

DataFrame class representing a two-dimensional, size-mutable, tabular data structure with labeled axes (rows and columns).

Attributes:

index (IndexLike): The row labels (index) of the DataFrame. Used for label-based row selection. columns (IndexLike): The column labels of the DataFrame. Used for label-based column selection.

property T: DataFrame

Return the transpose of the DataFrame, switching rows and columns.

The transpose (swap of axes) effectively converts columns to rows and rows to columns, maintaining the original data relationships while rotating the DataFrame structure.

Returns:
DataFrame: A new DataFrame instance where:
  • Original columns become the new index

  • Original index becomes the new columns

  • Data values are transposed accordingly

abs() DataFrame

Returns the absolute values for DataFrame

Returns:

DataFrame: Absolute values DataFrame

agg(method: Callable[[Collection[Any]], Any], axis: Literal[0, 1] = 0) Series

Aggregate data along specified axis using one or more operations.

Applies aggregation function to raw array values (rather than Series objects) along columns (axis=0) or rows (axis=1). Optimized for numerical aggregations.

Args:
method: Callable that takes array-like data and returns scalar
  • For axis=0: Receives column values as array

  • For axis=1: Receives row values as array

axis: Axis to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

Returns:

Series: Aggregation results.

all(axis: Literal[0, 1] | None = 0) Series | bool

Returns True if all values in the DataFrame are truthy.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

  • None: Aggregates along both axes returning a scalar

Returns:

Series | bool: True if all values are truthy, False otherwise.

any(axis: Literal[0, 1] | None = 0) Series | bool

Returns True if any value in the DataFrame is truthy.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

  • None: Aggregates along both axes returning a scalar

Returns:

Series | bool: True if any value is truthy, False otherwise.

apply(method: Callable[[Series], Any], axis: Literal[0, 1] = 0) Series

Apply a function along a DataFrame axis (columns or rows).

Processes either each column (axis=0) or each row (axis=1) as a Series object, applying the provided function to each Series. Returns a new Series with aggregated/transformed values.

Args:
method: Callable that takes a Series and returns a scalar value.
  • For axis=0: Receives each column as a Series

  • For axis=1: Receives each row as a Series

axis: Axis along which to apply:
  • 0: Apply to each column (default)

  • 1: Apply to each row

Returns:

Series: Results of applying the method along specified axis.

astype(new_type: type) DataFrame

Casts the DataFrame to a new type.

Args:

new_type (type): The type to cast to.

Returns:

DataFrame: A new DataFrame with the values cast to the new type.

property columns: Index

Returns the columns of the DataFrame.

Returns:

IndexLike: The columns of the DataFrame.

copy(*, deep: bool = True) DataFrame

Creates a copy of the DataFrame.

Args:

deep (bool, optional): If True, creates a deep copy. Otherwise, creates a shallow copy. Defaults to True.

Returns:

DataFrame: A copy of the DataFrame.

dot(other: DataFrame | Series | Collection) DataFrame | Series

Compute the matrix multiplication between the DataFrame and another DataFrame or Series.

Args:

other (DataFrame or Series): The other DataFrame or Series to multiply with.

Returns:

DataFrame or Series: The result of the matrix multiplication.

Raises:

ValueError: If the columns of the DataFrame do not match the index of the other DataFrame/Series. TypeError: If the other object is not a DataFrame or Series.

head(n: int = 5) DataFrame

Returns the first n rows.

Args:

n (int, optional): Number of rows to return. Defaults to 5.

Returns:

DataFrame: A new DataFrame containing the first n rows.

idxmax(axis: Literal[0, 1] = 0) Series

Returns the labels of the maximum values.

Args:
axis: Axis to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

Returns:

Series: The labels of the maximum values

idxmin(axis: Literal[0, 1] = 0) Series

Returns the labels of the minimum values.

Args:
axis: Axis to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

Returns:

Series: The labels of the minimum values

iloc: IlocDataFrameIndexer
property index: Index

Returns the index of the DataFrame.

Returns:

IndexLike: The index of the DataFrame.

iterrows() Generator[tuple[int | float | complex | str | bytes | bool, Series]]

Iterate over DataFrame rows as (index, Series) pairs.

Provides an efficient way to loop through rows of the DataFrame, returning both the index label and the row data as a Series for each iteration.

Returns:
Generator[tuple[Scalar, Series]]: A generator yielding tuples containing:
  • Scalar: The label of the current row

  • Series: Row data

loc: LocDataFrameIndexer
map(func: Callable) DataFrame

Applies a function to each value in the DataFrame.

Args:

func (Callable): The function to apply.

Returns:

DataFrame: A new DataFrame with the results of the function applied.

max(axis: Literal[0, 1] | None = 0) Series | int | float | complex | str | bytes | bool

Returns the maximum value in the DataFrame.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

  • None: Aggregates along both axes returning a scalar

Returns:

Series | Scalar: The maximum values along the axis

mean(axis: Literal[0, 1] | None = 0) Series | int | float | complex | str | bytes | bool

Computes the mean of the Series.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

  • None: Aggregates along both axes returning a scalar

Returns:

Series | float: Axis mean

median(axis: Literal[0, 1] | None = 0) Series | int | float | complex | str | bytes | bool

Return the median (middle value) of numeric data, using the common “mean of middle two” method. If data is empty, StatisticsError is raised. data can be a sequence or iterable.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

  • None: Aggregates along both axes returning a scalar

Returns:

Series | float | int: Axis median

min(axis: Literal[0, 1] | None = 0) Series | int | float | complex | str | bytes | bool

Returns the minimum value in the DataFrame.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

  • None: Aggregates along both axes returning a scalar

Returns:

Series | Scalar: The minimum values along the axis

mode(axis: Literal[0, 1] = 0) Series

Return the single most common data point from discrete or nominal data. The mode (when it exists) is the most typical value and serves as a measure of central location.

Args:
axis: Axis to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

Returns:

Series: Axis mode

quantiles(*, n=4, method: Literal['exclusive', 'inclusive'] = 'exclusive', axis: Literal[0, 1] = 0) Series

Divide data into n continuous intervals with equal probability. Returns a list of n - 1 cut points separating the intervals.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

Returns:

Series: Series of lists containing quantiles

property shape: tuple[int, int]
std(xbar=None, axis: Literal[0, 1] = 0) Series | int | float | complex | str | bytes | bool

Return the sample standard deviation (the square root of the sample variance). See variance() for arguments and other details.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

Returns:

Series: Standard deviations along axis

sum(axis: Literal[0, 1] | None = 0) Series | int | float | complex | str | bytes | bool

Returns the sum of the values in the DataFrame.

Args:
axis: AxisOrNone to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

  • None: Aggregates along both axes returning a scalar

Returns:

Series | Scalar: The sum of the values along the axis

tail(n: int = 5) DataFrame

Returns the last n rows.

Args:

n (int, optional): Number of rows to return. Defaults to 5.

Returns:

DataFrame: A new DataFrame containing the last n rows.

to_dict(orient: Literal['dict', 'list', 'records'] = 'dict')

Converts the DataFrame to a dictionary.

Args:
orient str {dict, list, records}: Determines the type of the values of the

dictionary.

Returns:

dict[Scalar, Any]: A dictionary representation of the Series.

to_list() list[list[Any]]

Converts the DataFrame to a list.

Returns:

list[list[Any]]: A list of the Series values.

property values: Array[Array[Any]]

Return a list representation of the DataFrame.

Returns:

list: The values of the DataFrame.

var(xbar=None, axis: Literal[0, 1] = 0) Series | int | float | complex | str | bytes | bool

Return the sample variance of data, an iterable of at least two real-valued numbers. Variance, or second moment about the mean, is a measure of the variability (spread or dispersion) of data. A large variance indicates that the data is spread out; a small variance indicates it is clustered closely around the mean.

Args:
axis: Axis to aggregate along:
  • 0: Aggregate each column (default)

  • 1: Aggregate each row

Returns:

Series: Variances along axis

class lontras.Index(data: Index | Collection | Iterator, name: int | float | complex | str | bytes | bool | None = None)

Bases: Array

get_ilocs(key: int | float | complex | str | bytes | bool | list[int | float | complex | str | bytes | bool] | slice | Array | Series) int | list[int]
name: int | float | complex | str | bytes | bool | None
property values: list[Any]

Return a list representation of the Index.

Returns:

list: The values of the Index.

class lontras.Series(data: Series | Mapping | Collection | int | float | complex | str | bytes | bool | None = None, index: Index | Sequence[int | float | complex | str | bytes | bool] | None = None, name: int | float | complex | str | bytes | bool | None = None)

Bases: Sequence, Sized

Series class representing a one-dimensional labeled array with capabilities for data analysis.

Attributes:

name (Scalar): Name of the Series.

abs() Series

Returns the absolute values for Series

Returns:

Series: Absolute values Series

agg(func: Callable) Any

Applies an aggregation function to the Series’ values.

This method applies a given function to all the values in the Series. It is intended for aggregation functions that operate on a collection of values and return a single result.

Args:
func (Callable): The aggregation function to apply. This function

should accept an iterable (like a list or NumPy array) and return a single value.

Returns:

Any: The result of applying the aggregation function to the Series’ values.

all() bool

Returns True if all values in the Series are truthy.

Returns:

bool: True if all values are truthy, False otherwise.

any() bool

Returns True if any value in the Series is True.

Returns:

bool: True if any value is True, False otherwise.

append(other: Series | Mapping) Series

Appends other to the end of the Series

Args:

other (Series | Mapping): The data to append

Returns:

Series: A new Series with new data

argmax() int

Returns the index of the maximum value.

Returns:

int: The index of the maximum value.

argmin() int

Returns the index of the minimum value.

Returns:

int: The index of the minimum value.

astype(new_type: type) Series

Casts the Series to a new type.

Args:

new_type (type): The type to cast to.

Returns:

Series: A new Series with the values cast to the new type.

copy(*, deep: bool = True)

Creates a copy of the Series.

Args:

deep (bool, optional): If True, creates a deep copy. Otherwise, creates a shallow copy. Defaults to True.

Returns:

Series: A copy of the Series.

dot(other: Series | Collection) int | float | complex | str | bytes | bool

Performs dot product with another Series, ArrayLike or Scalar.

If other is a Series or a ArrayLike, performs the dot product between the two. If other is a Scalar, multiplies all elements of the Series by the scalar and returns the sum.

Args:

other (Series | ArrayLike | Scalar)

Returns:

Scalar: The dot product of the Series.

drop(indexes: int | float | complex | str | bytes | bool | list[int | float | complex | str | bytes | bool] | slice | Array | Series) Series

Removes the elements associated to labels and returns a new Series.

Args:

indexes (LocIndexes): Labels to remove

Returns:

Series: A new series with the removed values

find(val: Any) int | float | complex | str | bytes | bool | None

Finds the first label (key) associated with a given value in the Series.

Args:

val (Any): The value to search for.

Returns:
Scalar | None: The label (key) of the first occurrence of the value,

or None if the value is not found.

head(n: int = 5) Series

Returns the first n rows.

Args:

n (int, optional): Number of rows to return. Defaults to 5.

Returns:

Series: A new Series containing the first n rows.

idxmax() int | float | complex | str | bytes | bool | None

Returns the label of the maximum value.

Returns:

Scalar: The label of the maximum value.

idxmin() int | float | complex | str | bytes | bool | None

Returns the label of the minimum value.

Returns:

Scalar: The label of the minimum value.

ifind(val: Any) int | None

Finds the first integer position (index) of a given value in the Series.

Args:

val (Any): The value to search for.

Returns:
int | None: The integer position (index) of the first occurrence of the value,

or None if the value is not found.

iloc: IlocSeriesIndexer
property index: Index

Returns the index of the Series.

Returns:

IndexLike: The index of the Series.

iteritems() Generator[tuple[int | float | complex | str | bytes | bool, int | float | complex | str | bytes | bool]]
loc: LocSeriesIndexer
map(func: Callable[[int | float | complex | str | bytes | bool], int | float | complex | str | bytes | bool]) Series

Applies a function to each value in the Series.

Args:

func (Callable[[Scalar], Scalar]): The function to apply.

Returns:

Series: A new Series with the results of the function applied.

max() int | float | complex | str | bytes | bool

Returns the maximum value in the Series.

Returns:

Any: The maximum value.

mean() int | float | complex | str | bytes | bool

Computes the mean of the Series.

Returns:

float: Series mean

median() int | float | complex | str | bytes | bool

Return the median (middle value) of numeric data, using the common “mean of middle two” method. If data is empty, StatisticsError is raised. data can be a sequence or iterable.

Returns:

float | int: Series median

min() int | float | complex | str | bytes | bool

Returns the minimum value in the Series.

Returns:

Any: The minimum value.

mode() int | float | complex | str | bytes | bool

Return the single most common data point from discrete or nominal data. The mode (when it exists) is the most typical value and serves as a measure of central location.

Returns:

Any: Series mode

name: int | float | complex | str | bytes | bool | None
quantiles(*, n=4, method: Literal['exclusive', 'inclusive'] = 'exclusive') Collection[float]

Divide data into n continuous intervals with equal probability. Returns a list of n - 1 cut points separating the intervals.

Returns:

list[float]: List containing quantiles

reduce(func: Callable[[Any, tuple[int | float | complex | str | bytes | bool, int | float | complex | str | bytes | bool]], Any], initial: Any) Any

Reduces the Series using a function.

Args:

func (Callable[[Any, tuple[Scalar, Scalar]], Any]): The function to apply for reduction. initial (Any): The initial value for the reduction.

Returns:

Any: The reduced value.

reindex(index: Index | Sequence[int | float | complex | str | bytes | bool] | Iterator) Series

Sets the index of the Series.

Args:

value (IndexLike): The new index for the Series.

Raises:

ValueError: If the length of the new index does not match the length of the Series.

rename(name: int | float | complex | str | bytes | bool) Series

Renames the Series.

Args:

name (Scalar): The new name for the Series.

Returns:

Series: A new Series with the updated name (a copy).

property shape: tuple[int]

Return a tuple of the shape of the underlying data.

std(xbar=None) int | float | complex | str | bytes | bool

Return the sample standard deviation (the square root of the sample variance). See variance() for arguments and other details.

Returns:

float: Series standard deviation

sum() int | float | complex | str | bytes | bool

Returns the sum of the values in the Series.

Returns:

Any: The sum of the values.

tail(n: int = 5) Series

Returns the last n rows.

Args:

n (int, optional): Number of rows to return. Defaults to 5.

Returns:

Series: A new Series containing the last n rows.

to_dict() dict[int | float | complex | str | bytes | bool, Any]

Converts the Series to a dictionary.

Returns:

dict[Scalar, Any]: A dictionary representation of the Series.

to_list() list[Any]

Converts the Series to a list.

Returns:

list[Any]: A list of the Series values.

property values: Array

Return a list representation of the Series.

Returns:

list: The values of the Series.

var(xbar=None) int | float | complex | str | bytes | bool

Return the sample variance of data, an iterable of at least two real-valued numbers. Variance, or second moment about the mean, is a measure of the variability (spread or dispersion) of data. A large variance indicates that the data is spread out; a small variance indicates it is clustered closely around the mean.

Returns:

float: Series variance