texthero.representation.term_frequency¶
-
term_frequency
(s: pandas.core.series.Series, max_features: Union[int, NoneType] = None, return_feature_names=False)¶ Represent a text-based Pandas Series using term_frequency.
- Parameters
- sPandas Series
- max_featuresint, optional
Maximum number of features to keep.
- return_features_namesBoolean, False by Default
If True, return a tuple (term_frequency_series, features_names)
Examples
>>> import texthero as hero >>> import pandas as pd >>> s = pd.Series(["Sentence one", "Sentence two"]) >>> hero.term_frequency(s) 0 [1, 1, 0] 1 [1, 0, 1] dtype: object
To return the features_names:
>>> import texthero as hero >>> import pandas as pd >>> s = pd.Series(["Sentence one", "Sentence two"]) >>> hero.term_frequency(s, return_feature_names=True) (0 [1, 1, 0] 1 [1, 0, 1] dtype: object, ['Sentence', 'one', 'two'])