Home > Software engineering >  A problem concerning ordering issue using sort_vlue(pandas)
A problem concerning ordering issue using sort_vlue(pandas)

Time:12-01

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:

enter image description here

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)
  • Related