pandas 系列中所有元素中最大的元素

编程入门 行业动态 更新时间:2024-10-27 16:29:11
本文介绍了 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 系列中所有元素中最大的元素

本文发布于:2023-10-26 10:10:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529833.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   系列   pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!