为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Pandas 将多个语句链接在一起时遇到问题

使用 Pandas 将多个语句链接在一起时遇到问题

PIPIONE 2023-03-16 16:05:21
我正在尝试从 Excel 电子表格中过滤出多列以简化我工作中的一些任务。这是我认为最好的解决方案,无需多次编写和重写文件。我很确定它与 bigsplit 变量之前的变量有关。我也尝试过在 bigsplit 变量周围和内部使用或不使用括号。这是我的代码片段:file = "07-14-2020.xlsx"df=pd.read_excel(file)    disco2=df[df["Discontinued"] == 'N']    close2=df[df["Store Closeout"] == 'N']    oi2=df[df["Order Indicator+"] != 'S']    dropship2=df[df["Primary Vendor"] == 'VENDOR']        bigsplit = (df[(disco2) & (close2) & (oi2) & (dropship2)]) <--Error here使用 (&) 运算符和 (and) 运算符会出现以下错误。使用 AND 时的错误:ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().使用 & 时的错误:TypeError: unsupported operand type(s) for &: 'float' and 'float'
查看完整描述

1 回答

?
慕姐4208626

TA贡献1852条经验 获得超7个赞

好像你想要


disco2 = df["Discontinued"] == 'N'

close2 = df["Store Closeout"] == 'N'

oi2 = df["Order Indicator+"] != 'S'

dropship2 = df["Primary Vendor"] == 'VENDOR'

    

bigsplit = df[disco2 & close2 & oi2 & dropship2]

在这里我们得到可以与组合的布尔&系列。在您的原始代码中,您制作df切片。错误表示不清楚如何从数据框中获取布尔值。


查看完整回答
反对 回复 2023-03-16
  • 1 回答
  • 0 关注
  • 57 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信