pandas_select.column.AllStr¶
-
class
AllStr
(*, strict=False)[source]¶ Select columns with dtype
object
, andstring
if pandas version >= 1.0.0.- Parameters
strict (default False) – If True, filter out object dtypes.
- Raises
ValueError – If pandas version < 1.0.0 and
strict = True
Notes
Be aware that
strict=False
, the default, will select all object dtype columns. Columns with mixed types are stored with the object dtype!See also
Examples
>>> df = pd.DataFrame({"i": [1, 2], ... "o": ["a", 2], ... "obj_str": ["a", "b"], ... "str": ["a", "b"]}) >>> try: ... df = df.astype({"obj_str": "object", "str": "string"}) ... except TypeError: # pandas.__version__ < '1.0.0' ... df = df.astype({"obj_str": "object", "str": "object"}) >>> df i o obj_str str 0 1 a a a 1 2 2 b b >>> df[AllStr()] o obj_str str 0 a a a 1 2 b b >>> pd.__version__ >= '1.0.0' True >>> df[AllStr(strict=True)] str 0 a 1 b