python 读取Excel 取出表头(列名)

#获取文件的sheep_name
import pandas as pd
df=pd.read_excel('my.xlsx',engine='openpyxl',sheet_name='中国疫情') #如果存在多个sheets,sheet_name这个必须指定

print(df.columns.to_list()) #把列名以列表的方式输出

  

测试数据文件链接:

链接: https://pan.baidu.com/s/14pKMmt7aigdMsA_fomfrMQ  密码: ahtm


如果失效,可以留言
原文地址:https://www.cnblogs.com/liangliangzz/p/14283051.html