python - pandas 支持按列标签读取 Excel 数据吗?

标签 python excel pandas

  1. 显示我尝试读取的 Excel 文件。
  2. 显示我想要在非合法代码中执行的操作。
  3. 显示了我迄今为止一直在尝试的内容。

1) Excel 文件

           A   |   B   |   C
    1    Name1   Name2   Name3
    2    33      44      55
    3    23      66      77
    4    22      33      99

2)非法代码:

frame = pd.read_excel(path, 'Sheet1', parse_cols="Name1,Name2,Name3")

在示例中,我可以假设列名称是唯一的。

3)到目前为止尝试过:

到目前为止我一直在尝试使用parse_cols,但我不认为pandas支持我正在尝试做的事情。

最佳答案

the documentation ,不支持您正在尝试做的事情。您可以按列号或列名称选择列,但不能按列标签选择列:

parse_cols : int or list, default None

  • If None then parse all columns,

  • If int then indicates last column to be parsed

  • If list of ints then indicates list of column numbers to be parsed

  • If string then indicates comma separated list of column names and column ranges (e.g. “A:E” or “A,C,E:F”)

关于python - pandas 支持按列标签读取 Excel 数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24380260/

相关文章:

python - Scipy Spearman 相关系数在某些情况下为 NaN

python - if else 检查 Python 中的每个条件,即使一个条件的计算结果为真

VBA:不同的工作表,相同命名的单元格范围?

vba - 使用 “”编译语句的错误结束

python - 从 CSV 保存和加载后使用 .pivot() 会导致 KeyError

python - 在 Pandas 切片上设置值的正确方法

pandas - 导入带有用户格式化表格的 Excel 电子表格

python - "R6034 An application has made an attempt to load the C runtime library incorrectly"安装pygtk后

python - 使用参数列表在 GUI 中创建单选按钮

Excel 2列比较: duplicate in one column,但作为对唯一