简体   繁体   中英

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) . it gives me the result like this (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 :(

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] . And since your input argument is a function, that also explains your error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM