pandas 支持按列标签读取Excel数据吗? [英] Is reading Excel data by column labels supported in pandas?

查看:80
本文介绍了 pandas 支持按列标签读取Excel数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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")

在示例中,我可以假定列名是唯一的.

In the example I can assume that the column names are unique.

3)到目前为止已尝试:

3) Tried so far:

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

What I have been trying so far is to use parse_cols, but I don't think what I'm trying to do is supported by pandas.

推荐答案

Per the documentation, there is no support for what you are trying to do. You can select columns by column number or column name, but not by column label:

parse_cols : int或列表,默认为无

  • 如果为None,则解析所有列,

  • If None then parse all columns,

如果int则指示要解析的最后一列

If int then indicates last column to be parsed

如果为整数列表,则表示要解析的列号列表

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

如果字符串表示列名和列范围的逗号分隔列表(例如"A:E"或"A,C,E:F")

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

这篇关于 pandas 支持按列标签读取Excel数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆