You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从DataFrame.describe()结果中提取指定列的均值、极值?

问题解答

关于DataFrame.describe()的取值方式

describe()方法返回的本身就是一个DataFrame,所以你完全可以像操作普通DataFrame那样,用iloc、loc或者列名+索引的方式提取特定列的统计值。不过更高效的方式是直接对目标列调用单独的统计方法,没必要先生成完整的describe()结果。

针对merge3 DataFrame的具体操作

假设你的DataFrame名为merge3,以下是几种常用的取值方式:

方式一:基于describe()结果提取

首先生成统计结果并存储:

desc_result = merge3.describe()

然后按需提取:

  • 提取Favorite_Count列的均值:
    desc_result.loc['mean', 'Favorite_Count']
    
  • 用iloc提取第2列(假设Percent_Car_in_Color是第2列)的最小值:
    # describe()的索引顺序是count, mean, std, min, 25%, 50%, 75%, max,min对应索引3
    desc_result.iloc[3, 2]
    
  • 提取Favorite_Color_Percent列的最大值:
    desc_result.loc['max', 'Favorite_Color_Percent']
    

方式二:直接对列调用统计方法(推荐)

这种方式无需生成完整的统计结果,直接针对目标列获取所需值,更高效:

  • 获取Average_Clothing_in_Color的最小值:
    merge3['Average_Clothing_in_Color'].min()
    
  • 获取Percent_Car_in_Color的最大值:
    merge3['Percent_Car_in_Color'].max()
    
  • 获取Favorite_Count的均值:
    merge3['Favorite_Count'].mean()
    

内容的提问来源于stack exchange,提问作者IanAnthony1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 17:20:48