pd.read\u excel并不总是读取所有列

2024-09-29 19:23:16 发布

您现在位置:Python中文网/ 问答频道 /正文

任务是将excel的前五列读入数据框:

def cqtreader(spec_path, sheet):
    data = pd.read_excel(spec_path, sheet_name=sheet, header=None, usecols='A:F')

有时前几行中有一些不必要的数据。它改变了pd.read_excel的行为

案例1:熊猫读取4列而不是5列 enter image description hereenter image description here

案例2:删除第一个空行,熊猫读取所有5列: enter image description hereenter image description here

案例3:从单元格D2中删除字符串“VMS”,pandas读取所有5列: enter image description hereenter image description here

如何使熊猫始终阅读5列


Tags: 数据pathnamenonereaddatadefexcel

热门问题