2

I want to sort the excel file worksheet called "LTE_PrbUtil" and it has a column called "CELL" which is string descending. When I run the program and find some error:

  File "C:\Users\p4532\Desktop\QGIS_project\highloading.py", line 18, in <module> df = df.sort(columns="CELL")
  File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 3081, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'sort'`

Here is my code:

import shutil
import pandas as pd
import xlrd
xl=pd.ExcelFile("C:\Users\p4532\Desktop\QGIS_project\HighUtilCells_new.xlsx")                                                                           
df = xl.parse("LTE_PrbUtil")
df = df.sort(columns="CELL")

It seems the dataframe cannot recognize sort. Can anyone help?

0TTT0
  • 1,288
  • 1
  • 13
  • 23
Edwin Cheng
  • 63
  • 1
  • 8

1 Answers1

3

Use sort_values:

df = df.sort_values('CELL')
Scott Boston
  • 147,308
  • 15
  • 139
  • 187