dtoolkit.accessor.dataframe.drop_or_not#
- dtoolkit.accessor.dataframe.drop_or_not(df: DataFrame, /, drop: bool = True, **kwargs) DataFrame [source]#
Drop specified labels from rows or columns.
A sugary syntax wraps
drop()
:df.drop(**kwargs) if drop else df
- Parameters:
- dropbool, default True
Choose to drop or not. If True will drop else don’t.
- **kwargs
See the documentation for
drop()
for complete details on the keyword arguments.
- Returns:
- DataFrame
If
drop=True
will execute else return the original.
See also
Examples
>>> import dtoolkit >>> import pandas as pd >>> df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) >>> df a b 0 1 3 1 2 4 >>> df.drop_or_not(True, columns="b") a 0 1 1 2 >>> df.drop_or_not(False, columns=["a"]) a b 0 1 3 1 2 4