返回选定行python的列

时间:2021-03-25 04:06:48

标签: python-3.x excel pandas openpyxl

我有一个使用 OpenPyXL 管理的 Excel 电子表格,它看起来像这样:

enter image description here

基本上,程序应该从第一行开始打印所选列的整列。

selectCol = input("Select col: ")
# lets say selectCol = 'Model'
# program will output: a, b, c

# lets say selectCol = 'Item'
# program will output: test, test2, test3

1 个答案:

答案 0 :(得分:0)

一旦 Excel 文件被加载到数据框 (df) 中并且 selectCol 已被“输入”,只需尝试:

df.loc[:, selectCol]
相关问题