pandas 系列中所有元素中最大的元素 [英] largest element all lists in Panda Series
本文介绍了 pandas 系列中所有元素中最大的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有个熊猫系列说
import pandas as pd
a = pd.Series([
[1, 2, 3, 4, 5],
[6, 7, 8, 3, 334],
[333, 4, 5, 3, 4]
])
我想在所有列表中找到最大的元素,即334,最简单的方法是什么?
I want to find the largest element in all lists, which is 334, what is the easy way to do it?
推荐答案
选项1
仅当元素实际上是list
时才起作用.这是因为sum
连接列表.这也可能很慢.
Option 1
Only works if elements are actually list
. This is because sum
concatenates lists. This is also likely very slow.
max(a.sum())
334
选项2
max
Option 2
minimal two tiered application of max
max(map(max, a))
334
选项3
仅当所有列表的长度相同
Option 3
Only works if all lists are same length
np.max(a.tolist())
334
选项4
max
在退绕发电机上的一种应用
Option 4
One application of max
on an unwound generator
max(x for l in a for x in l)
334
这篇关于 pandas 系列中所有元素中最大的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文