python Pandas : Get single max numeric value from df with floats and characters/alphas

标签 python pandas max dataframe

我想从下面的这个 df 中获取单个最大数值,其中包含 float 和字符/字母的组合。

这是我的 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]})

这是它的样子:

   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

预期结果:

43.0

目前我正在创建一个新的 df,它排除了“group1”和“group2”,但是必须有更好的方法来提取最大数值吗?

注意:此线程链接到 http://goo.gl/ZJoR9V

谢谢

最佳答案

使用 0.14.1,这是一种非常干净的方式

In [6]: df.select_dtypes(exclude=['object']).max().max()
Out[6]: 43.0

或者

In [6]: df.select_dtypes(exclude=['object']).unstack().max()
Out[6]: 43.0

关于 python Pandas : Get single max numeric value from df with floats and characters/alphas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25246885/

相关文章:

python - Azure Cosmos DB Python SDK : How to read change feed?

python - pyplot x轴被排序

python - 仅在同一天内重新取样

python - 如何删除列值为 NaN 的行的百分比

python - 使用列表作为名称和列表中元素的字符串

python - Shapely 中 MultiLineString 对象中 LineString 的顺序

java - 查找用户输入数组中的最小值和最大值 (Java)

arrays - 最大数量数组中总和小于或等于 k ​​的元素

elasticsearch - 如何在Elasticsearch中获取返回结果的最大日期值

python - 使用滚动窗口 Pandas 计算百分位数