soh*_*shi -3 python excel xls xlrd xlsx
我的excel数据是这样的:
A B C
1 RAM 53.44 576
2 MOHAN 74.34 345
3 KISHAN 76.65 285
Run Code Online (Sandbox Code Playgroud)
如何从电子表格中提取标题内容?
你的问题真的不清楚。但是,您可以使用Pandas库来读取文件 excel 格式。
import pandas as pd
print(pd.read_excel('file.xlsx').columns)
Run Code Online (Sandbox Code Playgroud)
调用以.columns列出所有列的标题
输出示例:
Index(['id', 'email','server','profession'], dtype='object')
编辑:
好的,现在我看到您首先对不符合熊猫数据结构的行感到很奇怪。最简单的解决方案是跳过前两行。然后将其导入 panadasDataFrame
用于skiprows跳过前 n 行。在你的情况下 2
import pandas as pd
print(pd.read_excel('file.xlsx',skiprows=2).columns)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14668 次 |
| 最近记录: |