【问题标题】:Pandas search max value in certain row range in Column熊猫在列中的特定行范围内搜索最大值
【发布时间】:2022-01-27 09:05:59
【问题描述】:

我有 5 列 x 行的系列数据

import pandas as pd
data = {'name' : ['bill', 'joe', 'steve', 'ana', 'john', 'ray'],
    'test1' : [85, 75, 85, 87,75, 81],
    'test2' : [35, 45, 83, 35, 45, 83],
    'test3' : [51, 61, 45, 51, 91, 45],
    'Highscore' : [85 , 75, 85, 87, 91, 83],
}
frame = pd.DataFrame(data)
print(frame)

这是打印结果

        name  test1  test2  test3  HighScore
    0   bill     85     35     51        85
    1    joe     75     45     61        75
    2  steve     85     83     45        85
    3    ana     87     35     51        87
    4   john     75     45     91        91
    5    ray     81     83     45        83

如何仅在特定行范围内获取 Column 中的最大值?

test1 from 0 to 3 --> 87
test2 from 3 to 5 --> 83
Highscore from 0 to 3 --> 87

【问题讨论】:

    标签: python python-3.x pandas


    【解决方案1】:

    您需要使用loc 选择值并获取max

    a = df.loc[0:3, 'test1'].max()
    print (a)
    87
    
    b = df.loc[3:5, 'test2'].max()
    print (b)
    83
    c = df.loc[0:3, 'HighScore'].max()
    print (c)
    87
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-04
      • 2015-10-22
      • 2021-06-15
      • 1970-01-01
      • 1970-01-01
      • 2022-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多