'How to display the record with the highest value?
I'm new to python and would like to know how do I display the record with the highest value.
I already figured out how to display the largest value, but I want to display the value concatenated with name(id).
For now, I did the following:
import pandas as pd
data = pd.read_csv('datasets/kc_house_data.csv')
#what is the most expensive house (highest sale value)
print(max(data['price']))
That way it's only displaying the value, I want to display the record.
I also tried as follows:
print(data[['id', 'price']].sort_values('price', ascending=False).head(1))
This way it returned the name and value correctly, but I believe there is some way to do this using the max() function.
Can someone help me?
Solution 1:[1]
As mentioned in the comments, you can do that with:
data['id'][data['price']==data['price'].max()]
using the max function as needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rikyeah |
