liwca.drop_category#
- liwca.drop_category(dx, categories)[source]#
Remove one or more categories from a dictionary.
For binary dicts, terms that no longer belong to any remaining category are dropped automatically (per
dx_schema’s “drop terms with no categories” parser). For weighted dicts, all terms are preserved (a row of zeros is meaningful in a weighted dict).- Parameters:
dx (
pandas.DataFrame) – A dictionary DataFrame. Either binary (all int8) or weighted (all float64). Mixed dtypes raiseTypeError.categories (
stror list ofstr) – Category name(s) to remove.
- Returns:
A new dictionary DataFrame without the specified categories, validated against the schema matching the input dtype.
- Return type:
- Raises:
Examples
>>> import liwca >>> dx = liwca.create_dx({"sports": ["baseball", "hockey"], "weather": ["rain*", "snow"]}) >>> liwca.drop_category(dx, "weather") Category sports DicTerm baseball 1 hockey 1