Catalog.from_polars
Catalog.from_polars
classmethod
¶
from_polars(
df: DataFrame | LazyFrame,
token_col: str,
corpora: Collection[str],
normalize: bool = True,
) -> Catalog
Creates a Catalog of corpora from a Polars dataframe.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DataFrame | LazyFrame
|
A Polars DataFrame or LazyFrame containing corpus information. Rows are tokens and columns are their frequencies in different corpora |
required |
|
str
|
The column that contains the tokens (words, subwords, n-grams, etc.) |
required |
|
Collection[str]
|
The columns that include the token frequencies for each corpus |
required |
|
bool
|
Whether to normalize the corpus frequencies for each corpus so that they are in the range \([0, 1]\) and sum to 1. The original corpus frequencies will be preserved |
True
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
KeyError
|
If any column in |
ValueError
|
If fewer than two columns are provided in |