close

How to get the max/min value in Pandas DataFrame when nan value in it

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to get the max/min value in Pandas DataFrame when nan value in it 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 to get the max/min value in Pandas DataFrame when nan value in it?

  1. How to get the max/min value in Pandas DataFrame when nan value in it?

    if you dont use iloc or loc, it is simple as:
    df['column'].max()
    or
    df['column'][df.index.min():df.index.max()]
    or any kind of range in this second square brackets

  2. get the max/min value in Pandas DataFrame when nan value in it

    if you dont use iloc or loc, it is simple as:
    df['column'].max()
    or
    df['column'][df.index.min():df.index.max()]
    or any kind of range in this second square brackets

Method 1

You can use NumPy‘s help with np.nanmaxnp.nanmin :

In [28]: df
Out[28]: 
   A   B  C
0  7 NaN  8
1  3   3  5
2  8   1  7
3  3   0  3
4  8   2  7

In [29]: np.nanmax(df.iloc[:, 1].values)
Out[29]: 3.0

In [30]: np.nanmin(df.iloc[:, 1].values)
Out[30]: 0.0

Method 2

if you dont use iloc or loc, it is simple as:

df['column'].max()

or

df['column'][df.index.min():df.index.max()]

or any kind of range in this second square brackets

Conclusion

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