本文介绍了 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 系列中所有元素中最大的元素
发布评论