2

I'm still fairly new to Python and Pandas and wanted to see if this was possible using pandas. I've read online that the best approach would be using idxmax.

What I'm trying to do: Search through an excel file called 'Sample' - Check the 'Difference' column and find the highest value --> Grab the 'Metric' name and display into a notepad file/browser. Below, is a picture for reference.
enter image description here

Here is a small snippet that I have seen online, any assistance on how to do this would be appreciated.

Code:

metric_column = Metric[:,1].astype(int)
metric = metric_column[np.argmax(Difference)]
  • how are you loading your excel into pandas? – Yuca Aug 16 '18 at 16:01
  • Possible duplicate of [Pandas DataFrame - Find row where values for column is maximal](https://stackoverflow.com/questions/10202570/pandas-dataframe-find-row-where-values-for-column-is-maximal) – Yuca Aug 16 '18 at 16:06
  • I'm using df = pandas.read_excel & also @Yuca, I don't see that tutorial including anything using Excel. –  Aug 16 '18 at 16:17
  • ok, so my answers is based on the assumption that the metric column is at position 0, it should work! – Yuca Aug 16 '18 at 16:19
  • Thanks for the input! I will be trying your method. –  Aug 16 '18 at 16:20
  • did it work properly? – Yuca Aug 16 '18 at 16:43

1 Answers1

2

This should do it

df.iloc[df['Difference'].idxmax(), 0]
Yuca
  • 6,010
  • 3
  • 22
  • 42
  • please consider to accept the answer by clicking on the tick on the left side of the answer :) – Yuca Aug 22 '18 at 15:57