Tae Yamasaki
Tae Yamasaki

Reputation: 25

How to find the max value in a column and return that name from another column

I want to find the building with the maximum number of floors and return that building's name.

I use:

dframe.loc[dframe[15].idxmax()] and I get this error: AttributeError: 'str' object has no attribute 'loc'

I also get TypeError: reduction operation 'argmax' not allowed for this dtype

The number of floors is in column 15 and the name of the building is in column 2. Any direction about how to approach this problem is helpful. Thanks!

Expected output would be the row with building name in column 2 where the max value is in column 15

Sample Data

0   1   2   3   4   5   6   7   8   9   ... 32  33  34  35  36  37  38  39  40  

41
42  56  2018    HILTON SEATTLE  NonResidential  7802920020  1301 6TH AVE    SEATTLE WA  98101   47.60946    ... NaN 2689945 9178092 62538   6253815 0   356.6   2.8 Compliant   No Issue
43  57  2018    5TH & PINE  NonResidential  1975700200  1513 5TH AVE    SEATTLE WA  98101   47.6113 ... 493 2671369 9114711 0   0   0   24.3    0.1 Compliant   No Issue
44  58  2018    CENTURY SQUARE RETAIL   NonResidential  1975700365  1525 4TH AVE    SEATTLE WA  98101   47.61076    ... NaN 195653  667569  3756    375626  0   21.7    0.4 Compliant   No Issue
46  60  2018    MANN BUILDING/WILD GINGER/TRIPLE DOOR   NonResidential  1975700525  1401 3RD AVE    SEATTLE WA  98101   47.60886    ... 5459    1338469 4566856 110816

Upvotes: 0

Views: 58

Answers (1)

Tae Yamasaki
Tae Yamasaki

Reputation: 25

input: dframe[14].dtype output: dtype('O') input: dframe[14].astype(int)

input: dframe[14].dtype output: dtype('int64')

input: print(dframe.loc[dframe[14].idxmax()][2])

Upvotes: 1

Related Questions