Python只读特定列excel表(按列名称)

Python只读特定列excel表(按列名称),python,excel,pandas,Python,Excel,Pandas,我有一个excel表格包含许多列 Col1 Col2 Col3 1 2 A 2 2 B 3 2 B 我使用pandas read_excel并使用“usecols”按索引读取列。只是想知道是否有任何方法可以通过名称来阅读这些列?例如,在这个例子中,Col2和Col3 import pandas as pd df = pd.read_excel(file_path, sheet_name=sheet_name, usecols="A

我有一个excel表格包含许多列

Col1 Col2 Col3
  1    2     A
  2    2     B
  3    2     B
我使用pandas read_excel并使用“usecols”按索引读取列。只是想知道是否有任何方法可以通过名称来阅读这些列?例如,在这个例子中,Col2和Col3

import pandas as pd
df = pd.read_excel(file_path, sheet_name=sheet_name, usecols="A,C")

如果需要
Col2
Col3
的,可以使用以下代码:

将熊猫作为pd导入
df=pd.read\u excel(文件路径,工作表名称=工作表名称,usecols=['Col2','Col3']))
或者,您可以使用:

将熊猫作为pd导入
df=pd.read\u excel(文件路径,工作表名称=工作表名称)[['Col2','Col3']]

usecols=['Col2','Col3']