Skip to content

bodo.pandas.BodoDataFrame.filter

BodoDataFrame.filter(items=None, like=None, regex=None, axis=None)
Subset the BodoDataFrame according to the specified (column) labels. This does not raise an error if a provided label is not in the dataframe.

Parameters

items: list-like, default None: Keep column labels that are in items.

like : str, default None: Keep column labels for which like is found in the column label string.

regex: str (regular expression), default None: Keep column labels for which re.search(regex, label) == True.

Exactly one of the above parameters must be provided, else a TypeError will be raised.

Setting the axis parameter will trigger a fallback to pandas.DataFrame.filter if a value other than None, 1, or "columns" is provided.

Returns

BodoDataFrame

Example

Using items:

import bodo.pandas as bd

bdf = bd.DataFrame(
    {
        "A": [0, 1, 2, 3, 4],
        "BB": [5, 6, 7, 8, 9],
        "CAC": [10, 11, 12, 13, 14]
    }
)

bdf_filtered = bdf.filter(items=("BB", "CAC", "D"))
print(bdf_filtered)

Output:

   BB  CAC
0   5   10
1   6   11
2   7   12
3   8   13
4   9   14

Using like:

import bodo.pandas as bd

bdf = bd.DataFrame(
    {
        "A": [0, 1, 2, 3, 4],
        "BB": [5, 6, 7, 8, 9],
        "CAC": [10, 11, 12, 13, 14]
    }
)

bdf_filtered = bdf.filter(like="A")
print(bdf_filtered)

Output:

   A  CAC
0  0   10
1  1   11
2  2   12
3  3   13
4  4   14