object#
- skrub.selectors.object()[source]#
Select columns whose dtype is
object(pandas) orpl.Object(polars).Note that object columns may contain mixed types (e.g., strings and numbers) and are broader than string columns. Use this selector when you specifically need object-typed columns, and prefer more specific selectors like
string()orcategorical().See also
stringSelect string columns (preferred for text data). Use this instead of object() for text columns.
categoricalSelect categorical columns.
has_dtypeSelect columns whose dtype matches specific dtypes.
Notes
Warning
The behavior of string columns may change depending on the pandas version:
Before pandas 3.0: String columns may have the
objectdtypeFrom pandas 3.0 onwards: String columns have only the
stringdtype
This selector selects all
objectdtype columns regardless of content, including mixed-type columns. For text data, preferstring()which is more selective.Examples
>>> from skrub import selectors as s >>> import pandas as pd >>> df = pd.DataFrame( ... dict( ... mixed=pd.Series(['A', 10]), ... numeric=pd.Series([1, 2]), ... string=pd.Series(['A', 'B']).convert_dtypes(), ... ) ... ) >>> df.dtypes mixed object numeric int64 string ... dtype: object
Select object dtype columns (note: can contain mixed types):
>>> s.select(df, s.object()) mixed 0 A 1 10
Prefer string() for text columns:
>>> s.select(df, s.string()) string 0 A 1 B