gpt4 book ai didi

python - Pandas:通过提供标题名称来读取列

转载 作者:太空宇宙 更新时间:2023-11-03 20:12:31 25 4
gpt4 key购买 nike

我需要从 Excel 工作表中检索一列。下面的表格有 4 个标题,即 4 列。我需要检索列 h3。有什么办法可以用 Pandas 做到这一点吗?

h1  h2  h3  h4
2 Q 21 20.3
1 A 32 2.3
3 W 21 34.2
9 R 42 9.3

最佳答案

首先需要通过read_excel创建DataFrame - sheetname 不需要指定是否需要文件的第一个sheetname:

df = pd.read_excel('File.xlsx')

用于通过[]选择系列:

s = df['h3']

用于通过双[]选择一列DataFrame:

df1 = df[['h3']]

关于python - Pandas:通过提供标题名称来读取列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58638149/

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