df = pd.read_excel(excelName)
df.columns=df.columns.str.strip()
print(df.columns.tolist())
# print result is ['序号', '学号', '姓名', '文件位置', '邮箱地址']
print(df.loc['文件位置'])
It seems I have the column named '文件位置' But when I locate this column by loc, it raises key error.
locallows indexing in both dimensions. The format isdf.loc[row_indexer, col_indexer].df['文件位置']would be equivalent todf.loc[:, '文件位置']notdf.loc['文件位置']which is looking for a row labeled '文件位置' not a column. This is covered in the accepted answer of the linked duplicate.