Skip to main content
 首页 » 编程设计

python之使用 pandas 对 excel 列进行排序

2025年01月19日20itcoder

<分区>

我想对名为“LTE_PrbUtil”的 excel 文件工作表进行排序,它有一个名为“CELL”的列,该列按字符串降序排列。 当我运行程序并发现一些错误时:

  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'` 

这是我的代码:

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") 

数据框似乎无法识别排序。 谁能帮忙?