我有以下数据框:
Join_Count 1
LSOA11CD
E01006512 15
E01006513 35
E01006514 11
E01006515 11
E01006518 11
...
但是当我尝试对它进行排序时:
BusStopList.sort("LSOA11CD",ascending=1)
我得到以下内容:
Key Error: 'LSOA11CD'
如何通过LSOA列或者没有标题的数字列对其进行排序?
以下是Python关于此数据框的信息:
<class 'pandas.core.frame.DataFrame'>
Index: 286 entries, E01006512 to E01033768
Data columns (total 1 columns):
1 286 non-null int64
dtypes: int64(1)
memory usage: 4.5+ KB
答案 0 :(得分:2)
'LSOA11CD'是索引的名称,1是列的名称。所以你必须使用排序索引(而不是sort_values):
BusStopList.sort_index(level="LSOA11CD", ascending=True)