我正在從SIPRI閱讀文件。它讀入熊貓和數據框被創建,我可以顯示它,但是當我嘗試按列排序時,我得到一個KeyError
。下面是代碼和錯誤:大熊貓閱讀和整理文件內容
import os
import pandas as pd
os.chdir('C:\\Users\\Student\\Documents')
#Find the top 20 countries in military spending by sorting
data = pd.read_excel('SIPRI-Milex-data-1949-2016.xls',
header = 0, index_col = 0, sheetname = 'Current USD')
data.sort_values(by = '2016', ascending = False)
KeyError: '2016'