【发布时间】:2021-08-26 22:54:56
【问题描述】:
有一个列列表,如果我要删除的行全部为零。随着计划数量的变化动态生成列表。 dmt_clean 是数据框。
dmt_clean.head()
OptionNumber TradeCategory 4015-7 4017-7 4019-7 4025-7 4030-6
0 1 Doors - Exterior 280.226822 280.226822 280.226822 280.226822 280.226822
1 1 Hardware 175.99 175.54 184.25 226.49 267.82
2 1 Trim - Interior 1818.783178 1904.233178 2252.523178 2589.283178 3323.953178
3 70000 Trim - Interior 0 0 0 0 0
4 70002 Trim - Interior 0 0 0 0 0
# get list of only plan number columns
l_plan_cols = []
for c in dmt_clean.columns:
if re.search('\d{4}-\d{1}', c):
l_plan_cols.append(c)
dmt_clean[l_plan_cols] == 0
4015-7 4017-7 4019-7 4025-7 4030-6
0 False False False False False
1 False False False False False
2 False False False False False
3 True True True True True
4 True True True True True
5 True True False True True
6 False False False True False
【问题讨论】:
-
df[~df.all(axis=1)] -
这个answer来自副本。