Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set no. of rows limit for pandas dataframe Maximum function

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)) 
like image 521
Bala Avatar asked Sep 04 '17 07:09

Bala


People also ask

How do you get max rows in pandas?

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.

What is the max rows in pandas DataFrame?

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.

How do I reduce the number of rows in pandas?

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.


1 Answers

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
like image 142
jezrael Avatar answered Oct 06 '22 01:10

jezrael