Home > Software design >  how i can find max price and company name
how i can find max price and company name

Time:03-18

df_max = df.loc[df['price'].max(),['make','price']]


ValueError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/pandas/core/indexes/range.py in get_loc(self, key, method, tolerance) 384 try: --> 385 return self._range.index(new_key) 386 except ValueError as err:

ValueError: 45400 is not in range

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last) 7 frames /usr/local/lib/python3.7/dist-packages/pandas/core/indexes/range.py in get_loc(self, key, method, tolerance) 385 return self._range.index(new_key) 386 except ValueError as err: --> 387 raise KeyError(key) from err 388 raise KeyError(key) 389 return super().get_loc(key, method=method, tolerance=tolerance)

KeyError: 45400.0

CodePudding user response:

You can use this to select the make and price from a row that has the highest price value.

df[['price', 'make']].loc[df.price == df.price.max()]

CodePudding user response:

I think boolean indexing is what you are trying to achieve.

df_max = df.loc[df["price"] == df["price"].max(), ["make", "price"]]
  • Related