pandas 如何设置没有。大熊猫数据帧的行数限制最大函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46032263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 04:23:25 来源:igfitidea点击:
How to set no. of rows limit for pandas dataframe Maximum function
提问by Bala
I have 100 rows in column B but I want to find Maximum value for only 99 rows.
我在 B 列中有 100 行,但我只想找到 99 行的最大值。
If I use the below code it returns maximum value from 100 rows instead of 99 rows:
如果我使用下面的代码,它会从 100 行而不是 99 行返回最大值:
print(df1['noc'].max(axis=0))
回答by jezrael
Use head
or iloc
for select first 99
values and then get max
:
print(df1['noc'].head(99).max())
Or as commented IanS
:
或如评论IanS
:
print (df1['noc'].iloc[:99].max())
Sample:
样本:
np.random.seed(15)
df1 = pd.DataFrame({'noc':np.random.randint(10, size=15)})
print (df1)
noc
0 8
1 5
2 5
3 7
4 0
5 7
6 5
7 6
8 1
9 7
10 0
11 4
12 9
13 7
14 5
print(df1['noc'].head(5).max())
8
print (df1['noc'].iloc[:5].max())
8
print (df1['noc'].values[:5].max())
8