gpt4 book ai didi

python - Pandas 是否支持按列标签读取 Excel 数据?

转载 作者:行者123 更新时间:2023-11-28 22:49:03 27 4
gpt4 key购买 nike

  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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com