pandas python - “布尔系列键将被重新索引以匹配数据帧索引。从 ipykernel 导入 kernelapp 作为应用程序”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49096311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python - "Boolean Series key will be reindexed to match DataFrame index. from ipykernel import kernelapp as app"
提问by Mark Wekking
menu_sub= menu[menu["Trans Fat"]==0][menu["Cholesterol (% Daily Value)"]==0][menu["Cholesterol (% Daily Value)"]==0]
returns: "Boolean Series key will be reindexed to match DataFrame index. from ipykernel import kernelapp as app"
返回:“布尔系列键将被重新索引以匹配数据帧索引。从 ipykernel 导入 kernelapp 作为应用程序”
After searching for a solution people suggested I used '&', but after using that I get a other error..
在寻找解决方案后,人们建议我使用“&”,但使用后我得到了另一个错误..
menu_sub= menu[menu["Trans Fat"]==0 & menu["Cholesterol (% Daily Value)"]==0 & menu["Cholesterol (% Daily Value)"]==0]
returns: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
返回: Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
Is there a way to do this in one line? or do have to create 3 different lines?
有没有办法在一行中做到这一点?还是必须创建 3 条不同的线路?
回答by piRSquared
First you were chain boolean slicing where the boolean series you were slicing with were based off of the original and the slices you were chaining kept getting smaller.
首先,您是链布尔切片,其中您切片的布尔系列基于原始切片,并且您正在链接的切片越来越小。
Second, you need to wrap your boolean series in parentheses.
其次,您需要将布尔系列括在括号中。
menu_sub= menu[
(menu["Trans Fat"] == 0) &
(menu["Cholesterol (% Daily Value)"] == 0) &
(menu["Cholesterol (% Daily Value)"] == 0)
]
But now you can see you are repeating one condition twice, which I don't understand.
但是现在你可以看到你重复了一个条件两次,我不明白。