[英]Python Pandas: Get single max numeric value from df with floats and characters/alphas
I want to get the single max numeric value from this df below which contains a mix of floats and characters/alphas. 我想从此df中获取单个最大数值,该数值包含浮点数和字符/字母的混合。
Here is my df: 这是我的df:
df = pd.DataFrame({'group1': ['a','a','a','b','b','b','c','c','d','d','d','d','d'],
'group2': ['c','c','d','d','d','e','f','f','e','d','d','d','e'],
'value1': [1.1,2,3,4,5,6,7,8,9,1,2,3,4],
'value2': [7.1,8,9,10,11,12,43,12,34,5,6,2,3]})
This is what it looks like: 看起来是这样的:
group1 group2 value1 value2
0 a c 1.1 7.1
1 a c 2.0 8.0
2 a d 3.0 9.0
3 b d 4.0 10.0
4 b d 5.0 11.0
5 b e 6.0 12.0
6 c f 7.0 43.0
7 c f 8.0 12.0
8 d e 9.0 34.0
9 d d 1.0 5.0
10 d d 2.0 6.0
11 d d 3.0 2.0
12 d e 4.0 3.0
Expected outcome: 预期结果:
43.0
At the moment I am creating a new df which excludes "group1" and "group2" but there must be a better way to pull the max numeric value? 目前,我正在创建一个新的df,其中不包括“ group1”和“ group2”,但是必须有更好的方法来提取最大数值吗?
Note: this thread is linked to http://goo.gl/ZJoR9V 注意:该线程链接到http://goo.gl/ZJoR9V
Thanks 谢谢
Using 0.14.1, this is a nice clean way 使用0.14.1,这是一种很好的清洁方法
In [6]: df.select_dtypes(exclude=['object']).max().max()
Out[6]: 43.0
Or 要么
In [6]: df.select_dtypes(exclude=['object']).unstack().max()
Out[6]: 43.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.