小编use*_*628的帖子

Pandas - 根据其他列中的最小值获取值

我有以下数据框:

      Q        GDP  
248 2008q3  14891.6 
249 2008q4  14577.0 
250 2009q1  14375.0 
251 2009q2  14355.6 
Run Code Online (Sandbox Code Playgroud)

我想要 GDP 最低的 Q 值。

基于这篇文章,根据另一列熊猫数据框提取列值,我尝试了以下操作:

    df = df.loc[df['GDP'].min(),'Quarters'].iloc[0]
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误消息:

    TypeError: cannot do label indexing on <class 'pandas.indexes.range.RangeIndex'> with these indexers [14355.6] of <class 'numpy.float64'>
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激!

python pandas

2
推荐指数
1
解决办法
1473
查看次数

标签 统计

pandas ×1

python ×1