7

I have 100 rows in column B but I want to find Maximum value for only 99 rows.

If I use the below code it returns maximum value from 100 rows instead of 99 rows:

print(df1['noc'].max(axis=0)) 
1
  • 2
    df1['noc'].iloc[0:99].max(axis=0)? Commented Sep 4, 2017 at 7:30

1 Answer 1

10

Use head or iloc for select first 99 values and then get max:

print(df1['noc'].head(99).max()) 

Or as commented 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.