我想运行特定列的binom_test作为每一行的参数。我已经完成了一些代码,并且出现了相同的错误,如下所示:
from scipy.stats import binom_test
bi
Cij From To Count p
0 156 A B 61 0.25
1 4 A C 1 0.25
2 6 A D 3 0.25
3 3 A E 2 0.25
bi['bi'] = bi.apply(lambda x: binom_test(bi['Count'],
bi['Cij'],
bi['p'],
alternative= 'greater'), axis=1)
但是,错误出来了:
~\AppData\Roaming\Python\Python37\site-packages\scipy\stats\morestats.py in binom_test(x, n, p, alternative)
2412 n = np.int_(n)
2413 else:
-> 2414 raise ValueError("Incorrect length for x.")
2415
2416 if (p > 1.0) or (p < 0.0):
ValueError: ('Incorrect length for x.', 'occurred at index 0')
另一行代码:
bi['bi'] = binom_test(x=bi['Count'],n=bi['Cij'],p=bi['p'],alternative='greater')
错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1208-824c68319c1b> in <module>
----> 1 bi['bi_1'] = binom_test(x=bi['Count1'],n=bi['Cij'],p=bi['p'],alternative='greater')
~\AppData\Roaming\Python\Python37\site-packages\scipy\stats\morestats.py in binom_test(x, n, p, alternative)
2412 n = np.int_(n)
2413 else:
-> 2414 raise ValueError("Incorrect length for x.")
2415
2416 if (p > 1.0) or (p < 0.0):
ValueError: Incorrect length for x.
谁能帮我这个?
由于您使用的是lambda应用,因此变量x
为一行,您需要使用该变量:
bi['bi'] = bi.apply(lambda x: binom_test(x['Count'],
x['Cij'],
x['p'],
alternative= 'greater'), axis=1)
bi
Cij From To Count p bi
0 156 A B 61 0.25 0.000072
1 4 A B 1 0.25 0.683594
2 6 A B 3 0.25 0.169434
3 3 A B 2 0.25 0.156250
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句