Catalog.from_dataframe
Catalog.from_dataframe
classmethod
¶
from_dataframe(
df: IntoFrame,
token_col: str,
corpora: Collection[str],
normalize: bool = True,
) -> Catalog
Creates a Catalog of corpora from any dataframe supported by Narwhals.
The dataframe is converted to Polars before the catalog is constructed.
Warning
The catalog's engine is backed by Polars. Any dataframe it returns is a Polars dataframe, regardless of the backend that the data came from.
Polars dataframes are used as given, so a LazyFrame stays lazy. Dataframes from other lazy backends, like DuckDB and PySpark, are materialized in memory.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
IntoFrame
|
A dataframe containing corpus information, from any backend supported by Narwhals. 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 |
|---|---|
TypeError
|
If |
KeyError
|
If |
KeyError
|
If any column in |
ValueError
|
If fewer than two columns are provided in |