【发布时间】:2022-11-29 17:30:37
【问题描述】:
尝试将以下代码放入一个衬里 -
l=[]
for i in df.columns:
if df[x] == bool:
l.append(i)
else:
continue
还有一些随机的 DataFrame。 工作正常,在这里!
以下是我的尝试 -
l = [x if df[x] == bool else continue for x in df.columns]
#and
l = [x if df[x] == bool for x in df.columns]
这些显示错误!
【问题讨论】:
-
你能解释一下你的代码吗?您需要布尔列
df.select_dtypes(bool).columns.tolist()吗?
标签: python python-3.x pandas list one-liner