如何在Pandas DataFrame中获取nan/min值时的最大值/最小值 [英] How to get the max/min value in Pandas DataFrame when nan value in it
本文介绍了如何在Pandas DataFrame中获取nan/min值时的最大值/最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于我的pandas数据框的一列具有nan
值,所以当我想获取该列的最大值时,它只是返回错误.
Since one column of my pandas dataframe has nan
value, so when I want to get the max value of that column, it just return error.
>>> df.iloc[:, 1].max()
'error:512'
如何跳过该nan
值并获得该列的最大值?
How can I skip that nan
value and get the max value of that column?
推荐答案
您可以将NumPy
的帮助与 np.nanmin
:
You can use NumPy
's help with np.nanmax
, np.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
这篇关于如何在Pandas DataFrame中获取nan/min值时的最大值/最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文