单个 Dataframe 单元格中系列的最大值 [英] Max value of a Series in a single Dataframe cell

查看:88
本文介绍了单个 Dataframe 单元格中系列的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,其中每一行在 单列 中包含一个系列.

I have a Dataframe where each row contains a Series in a single column.

             col1    
row1     [34,55,11,8]
row2     [36,76,69,6]
row3     [77,31,40,55]
row4     [51,41,26,30]

我想获取系列中每个值的最大值并在新列中生成该值.

I want to get the max of each value in the series and produce that in a new column.

        col1                   max 
row1     [34,55,11,8]          55
row2     [36,76,69,6]          76
row3     [77,31,40,55]         77
row4     [51,41,26,30]         51

我的尝试:

df['max'] = df['values'].apply(lambda x:x.max())
df.head()

错误

ValueError: zero-size array to reduction operation maximum which has no identity

推荐答案

使用数据框构造函数重新创建您的 list 类型列

Using dataframe constructor re-create your list type columns

df['Max']=pd.DataFrame(df['values'].tolist(),index=df.index).max(1)

这篇关于单个 Dataframe 单元格中系列的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆