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))
Find Maximum Element in Pandas DataFrame's Row If the axis equals to 0, the max() method will find the max element of each column. On the other hand, if the axis equals to 1, the max() will find the max element of each row.
Set Max Number of Rows The default number is 60. As shown, if we have a data frame with more than 60 rows, 50 rows in the middle will be truncated. If we set the option larger than the number of rows of our data frame, all the rows will be displayed.
To drop a row or column in a dataframe, you need to use the drop() method available in the dataframe. You can read more about the drop() method in the docs here. Rows are labelled using the index number starting with 0, by default. Columns are labelled using names.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With