A Suresh
A Suresh

Reputation: 129

How to filter selected column with even numbers?

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

Upvotes: 2

Views: 2140

Answers (2)

Mutaz-MSFT
Mutaz-MSFT

Reputation: 806

df[df.B % 2 == 0]

output :

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

Upvotes: 1

U13-Forward
U13-Forward

Reputation: 71600

Just use modulo math like the below:

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

And now printing df would give the expected dataframe.

Upvotes: 2

Related Questions