简体   繁体   中英

How to find the maximum value of a column with pandas?

I have a table with 40 columns and 1500 rows. I want to find the maximum value among the 30-32nd (3 columns). How can it be done? I want to return the maximum value among these 3 columns and the index of dataframe.

print(Max_kVA_df.iloc[30:33].max())

在此处输入图片说明

Select values by positions and use np.max :

Sample : for maximum by first 5 rows:

np.random.seed(123)
df = pd.DataFrame(np.random.randint(10, size=(10, 3)), columns=list('ABC'))
print (df)
   A  B  C
0  2  2  6
1  1  3  9
2  6  1  0
3  1  9  0
4  0  9  3

print (df.iloc[0:5])
   A  B  C
0  2  2  6
1  1  3  9
2  6  1  0
3  1  9  0
4  0  9  3

print (np.max(df.iloc[0:5].max()))
9

hi you can refer this example

import pandas as pd

df=pd.DataFrame({'col1':[1,2,3,4,5],
  'col2':[4,5,6,7,8],
  'col3':[2,3,4,5,7]
})

print(df)

#print(df.iloc[:,0:3].max())# Mention range of the columns which you want, In your case change 0:3 to 30:33, here  33 will be excluded
ser=df.iloc[:,0:3].max()
print(ser.max())

Output

8

或者这样使用iloc

print(df.iloc[[30, 31], 2].max())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM