cascade.utils.tables#
- class cascade.utils.tables.CSVDataset(csv_file_path: str, read_csv_kwargs=None, *args: Any, **kwargs: Any)[source]#
-
Wrapper for .csv files.
- class cascade.utils.tables.FeatureTable(table: Union[TableDataset, DataFrame], *args: Any, **kwargs: Any)[source]#
-
Table dataset which allows to easily define and compute features
Example
import pandas as pd from cascade.utils.tables import FeatureTable df = pd.read_csv(r'data .csv', index_col=0) df # id count name # 0 0 1 aaa # 1 1 5 bbb # 2 2 0 ccc ft = FeatureTable(df) ft.get_features() # ['id', 'count', ' name'] ft.add_feature('square', lambda df: df['count'] * df['count']) def counts(df): return df['count'] * 2, df['count'] * 3 ft.add_feature(('count_2', 'count_3'), counts) ft.get_features() # ['id', 'count', ' name', 'square', ('count_2', 'count_3')] ft.get_table(['count', ('count_2', 'count_3')]) # count count_2 count_3 # 0 1 2 3 # 1 5 10 15 # 2 0 0 0
- __init__(table: Union[TableDataset, DataFrame], *args: Any, **kwargs: Any) None[source]#
-
- Parameters:
-
table (Union[TableDataset, pd.DataFrame]) – The table to wrap
- add_feature(name: Union[str, Tuple[str]], func: Callable[[DataFrame], Union[Series, Tuple[str]]], *args: Any, **kwargs: Any) None[source]#
-
Adds computable feature to the table in a lazy manner
- get_features() List[Union[str, Tuple[str]]][source]#
-
Returns the list of feature names with all computed features added before
- get_meta() List[Dict[Any, Any]][source]#
-
- Returns:
-
meta – A list where last element is this dataset’s metadata. Meta can be anything that is worth to document about the dataset and its data. This is done in form of list to enable cascade-like calls in Modifiers and Samplers.
- Return type:
-
Meta
- class cascade.utils.tables.TableDataset(*args: Any, t: Optional[Union[DataFrame, TableDataset]] = None, **kwargs: Any)[source]#
-
Wrapper for
DataFramewhich allows to manage metadata and perform validation- __init__(*args: Any, t: Optional[Union[DataFrame, TableDataset]] = None, **kwargs: Any) None[source]#
-
- Parameters:
-
t (optional) – pd.DataFrame or TableDataset to be set as table
- class cascade.utils.tables.TableFilter(dataset: TableDataset, mask: List[bool], *args: Any, **kwargs: Any)[source]#
-
Filter for table values
- __init__(dataset: TableDataset, mask: List[bool], *args: Any, **kwargs: Any) None[source]#
-
- Parameters:
-
-
dataset (TableDataset) – Dataset to be filtered.
-
mask (Iterable[bool]) – Binary mask to select values from table.
-