0

attached the data frame photo,trying the day,but getting error

Maximum pressure  Minimum pressure  Day
12                   21             2013/03/12
25                   14             2015/04/16
27                   18             2010/09/21 

df.loc[max(df['Maximum pressure '] -df['Minimum pressure ']),'Day']
Ch3steR
  • 20,090
  • 4
  • 28
  • 58
Swati Jha
  • 11
  • 2
  • 2
    `df.loc[(df['Maximum pressure '] -df['Minimum pressure ']).idxmax(),'Day']`---> `'2015/04/16'`? – Ch3steR Jun 16 '20 at 14:20
  • to add to Ch3ster's answer, you need to return the index of the highest value, the `max` of the two value will return a value of `11` that does not exists in your dataframe, there are several ways to do this, but the above is probably the most concise. – Umar.H Jun 16 '20 at 14:23
  • 1
    Does this answer your question? [Find row where values for column is maximal in a pandas DataFrame](https://stackoverflow.com/questions/10202570/find-row-where-values-for-column-is-maximal-in-a-pandas-dataframe) – Umar.H Jun 16 '20 at 14:23

1 Answers1

1

I would go about it like this: (inp = your df snippet from the question)

import pandas as pd

inp = [{'maximum pressure':12, 'minimum pressure':21,'Date':'2013/03/12'}, {'maximum pressure':25,'minimum pressure':14,'Date':'2015/04/16'}, {'maximum pressure':27,'minimum pressure':18,'Date':'2010/09/21'}]

df = pd.DataFrame(inp)

df['difference pressure']= df['maximum pressure']-df['minimum pressure']

df.loc[df['difference pressure'] == df['difference pressure'].max()]
Robert Redisch
  • 161
  • 1
  • 10