I want to find out a max value, so I use df.groupby('h_type').max()['h_price']
but it gives a strange result. Therefore, I use the following code and then find out there is an ordering issue
bond=pd.read_csv('/content/drive/MyDrive/test/datahistory/c.csv',index_col='h_type')
a=bond.loc['mansion']
aMax=a.sort_values(['h_price'],ascending=False)
aMax
Then it yields:
What kind of the problem may it be?
CodePudding user response:
Problem is column h_price
is not numeric, need:
bond=pd.read_csv('/content/drive/MyDrive/test/datahistory/c.csv',index_col='h_type')
bond['h_price'] = bond['h_price'].str.replace(',','.', regex=True).astype(float)
a=bond.loc['mansion']
aMax=a.sort_values(['h_price'],ascending=False)