[英]How can I make a Python function return only one of two values when using DataFrame.apply?
If I use this fuction line1.apply(sc.shapiro, axis=1)
.如果我使用这个函数line1.apply(sc.shapiro, axis=1)
。 it gives me the result like this (0.9815108776092529, 0.9715939164161682)
.它给了我这样的结果(0.9815108776092529, 0.9715939164161682)
。 I want to get only the second value, so I tried to write it like this line1.apply(sc.shapiro[1], axis=1)
but it never worked :(我只想得到第二个值,所以我试着像这样写line1.apply(sc.shapiro[1], axis=1)
但它从来没有工作:(
The problem is问题是
----> 1 line1.apply(sc.shapiro[1], axis=1)
TypeError: 'function' object is not subscriptable
Any suggestions?有什么建议?
You need to slice out the [1]
from the actual result, not the method argument: line1.apply(sc.shapiro, axis=1)[1]
.您需要从实际结果中切出[1]
,而不是方法参数: line1.apply(sc.shapiro, axis=1)[1]
。 And since your input argument is a function, that also explains your error message.由于您的输入参数是一个函数,这也解释了您的错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.