How to filter selected column with even numbers?

Viewed 560

I have dataframe as below and wanted to filter only column "B" with even numbers.

    A   B   C   D

0   9   15  64  28

1   93  29  8   73

2   40  36  16  11

3   88  62  33  72

4   49  51  54  77

Required Output:

    A   B   C   D
2   40  36  16  11
3   88  62  33  72
2 Answers

Just use modulo math like the below:

df[df['B'] % 2 == 0]

And now printing df would give the expected dataframe.

df[df.B % 2 == 0]

output :

    A   B   C   D
2   40  36  16  11
3   88  62  33  72
Related