close

How do I select and store columns greater than a number in pandas?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I select and store columns greater than a number in pandas in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I select and store columns greater than a number in pandas?

  1. How do I select and store columns greater than a number in pandas?

    Sample DF:
    In [79]: df = pd.DataFrame(np.random.randint(5, 15, (10, 3)), columns=list('abc')) In [80]: df Out[80]:

  2. select and store columns greater than a number in pandas

    Sample DF:
    In [79]: df = pd.DataFrame(np.random.randint(5, 15, (10, 3)), columns=list('abc')) In [80]: df Out[80]:

Method 1

Sample DF:

In [79]: df = pd.DataFrame(np.random.randint(5, 15, (10, 3)), columns=list('abc'))

In [80]: df
Out[80]:
    a   b   c
0   6  11  11
1  14   7   8
2  13   5  11
3  13   7  11
4  13   5   9
5   5  11   9
6   9   8   6
7   5  11  10
8   8  10  14
9   7  14  13

present only those rows where b > 10

In [81]: df[df.b > 10]
Out[81]:
   a   b   c
0  6  11  11
5  5  11   9
7  5  11  10
9  7  14  13

Minimums (for all columns) for the rows satisfying b > 10 condition

In [82]: df[df.b > 10].min()
Out[82]:
a     5
b    11
c     9
dtype: int32

Minimum (for the b column) for the rows satisfying b > 10 condition

In [84]: df.loc[df.b > 10, 'b'].min()
Out[84]: 11

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read