【发布时间】:2020-04-18 20:46:20
【问题描述】:
我必须处理一些从外部来源收到的xlsx。有没有更直接的方法可以在pandas 中加载xlsx,同时也跳过带有删除线的行?
目前我必须这样做:
import pandas as pd, openpyxl
working_file = r"something.xlsx"
working_wb = openpyxl.load_workbook(working_file, data_only=True)
working_sheet = working_wb.active
empty = []
for row in working_sheet.iter_rows("B", row_offset=3):
for cell in row:
if cell.font.strike is True:
p_id = working_sheet.cell(row=cell.row, column=37).value
empty.append(p_id)
df = pd.read_excel(working_file, skiprows=3)
df = df[~df["ID"].isin(empty)]
...
这有效,但只能通过两次检查每个 excel 表。
【问题讨论】:
-
读取文件时数据框如何显示 - 带有删除线的行,它们看起来不同吗?被破坏?还是像其他人一样的普通数字?图片或一些可重复的示例可能会有所帮助
标签: python-3.x pandas openpyxl