1

I created the data in the form of rows and columns from data in a text file using pandas in python. Now, I need to obtain the maximum value of grapes, oranges, and mangos as shown below:

       Key       Value
 0     Grapes    50
 1     Oranges   70
 2     Grapes    20
 3     Mangos    10
 4     Oranges   40
 5     Mangos    80
Niayesh Isky
  • 1,100
  • 11
  • 17
KIRAN KS
  • 11
  • 4
  • 1
    Welcome to SO! Have you already read [the documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.max.html) to see if it answers your question? – Niayesh Isky Mar 20 '19 at 03:33
  • Here 0,1,2,3,4,5 is index(row labels) and 50,70,20,10,40,80 is the values and Grapes,Oranges and Mangos are keys. – KIRAN KS Mar 20 '19 at 03:34
  • kindly check this https://stackoverflow.com/questions/15705630/python-getting-the-row-which-has-the-max-value-in-groups-using-groupby – Akhilesh_IN Mar 20 '19 at 03:41
  • I used df.groupby(['Key'], sort=False)['Value'].max() and I got the output. – KIRAN KS Mar 20 '19 at 07:52

1 Answers1

1
a=df[df['key']=='orange']

So a contains entries of data frame for oranges. Now you can extract the values. val=a['Value'].values and find the maximum: impprt numpy as np maximum=np.amax(val)

Tojra
  • 673
  • 5
  • 20