所以我有一个奇怪的样式的xls文件,但是我无能为力,所以我只需要解析它。

如您所见,我有一些合并的单元格。我想做的是为合并的单元格填充空值(“填充”),但还要保持空单元格不变。

EIM,C,NI1 Enescu_Ioan,EIM,S,NI11,Enescu_Ioan EIM,C,NI1 Enescu_Ioan,空EIM,C,NI1 Enescu_Ioan EIM,S,NI11,Enescu_Ioan EIM,C,NI1,Enescu_Ioan空 方式I现在加载文件是这样。

xl = pd.ExcelFile("data/file.xls")
df = xl.parse(0, header=None)

我也尝试过这样打开文件并访问合并的单元格,但是我得到了一个空列表。

book = xlrd.open_workbook("data/file.xls")
book.sheet_by_index(0).merged_cells # This is empty []

有什么办法可以实现?谢谢!

关于这个问题可能会有一些困惑,所以我会尽力解释。附件图像是较大文件的子集,其中各列可能以不同顺序出现。我想要实现的是一种区分合并单元格NAN值(在合并单元格中只有第一列具有值,其余均为nan)和空单元格NAN的方法。

问题来源:stackoverflow

excel = None if path.endswith('xlsx'): excel = pd.ExcelFile(xlrd.open_workbook(path), engine='xlrd') elif path.endswith('xls'): excel = pd.ExcelFile(xlrd.open_workbook(path, formatting_info=True), engine='xlrd') else: raise ValueError("Could not read this type of data") return excel def parse_excel(excel_file): sheet_0 = excel_file.book.sheet_by_index(0) df = excel_file.parse(0, header=None) return sheet_0, df def fill_merged_na(sheet, dataframe): for e in sheet.merged_cells: rl, rh, cl, ch = e base_value = sheet.cell_value(rl, cl) dataframe.iloc[rl:rh, cl:ch] = base_value return dataframe

一些重要的位会打开formatting_info设置为True的excel文件,以读取格式,例如合并的单元格和fill_merged_na函数,该函数仅填充合并的nan值,但保留初始的空单元格。

回答来源:stackoverflow

2020-03-24 17:57:06 企业邮箱发送邮件时,若出现投递失败产生退信,内容提示包含如下: the mta server of * reply:550 failed to meet SPF requirements 或者 the mta server of 163.com — 163mx01.mxmail.netease.com(220.181.14.141) reply:550 MI:SPF mx14,QMCowECpA0qTiftVaeB3Cg—.872S2 1442548128 http://mail.163.com/help 299119