Bal*_*ala 4 python dataframe pandas
我在 B 列中有 100 行,但我只想找到 99 行的最大值。
如果我使用下面的代码,它会从 100 行而不是 99 行返回最大值:
print(df1['noc'].max(axis=0))
Run Code Online (Sandbox Code Playgroud)
print(df1['noc'].head(99).max())
Run Code Online (Sandbox Code Playgroud)
或如评论IanS:
print (df1['noc'].iloc[:99].max())
Run Code Online (Sandbox Code Playgroud)
样本:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20395 次 |
| 最近记录: |