我需要从 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/