我有两个数据帧primary_tumor_df
和healthy_tissue_df
来执行Mann-Whitney U测试.我还从两个数据帧中删除了nan
个值.
Structure of primary_tumor_df
.
Structure of healthy_tissue_df
.
primary_tumor_df.dropna(inplace=True)
healthy_tissue_df.dropna(inplace=True)
This shows that there are no nan
or null values.
但在执行测试时,它给我带来了以下错误:
from scipy.stats import mannwhitneyu
p_value_dict = {}
for gene in primary_tumor_df.columns:
stats, p_value = mannwhitneyu(primary_tumor_df[gene], healthy_tissue_df[gene],
alternative='two-sided')
Error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[9], line 4
2 p_value_dict = {}
3 for gene in primary_tumor_df.columns:
----> 4 stats, p_value = mannwhitneyu(primary_tumor_df[gene],
5 healthy_tissue_df[gene],
6 alternative='two-sided')
7 p_value_dict[gene] = p_value
9 # converting into DataFrame
File ~/.local/lib/python3.10/site-packages/scipy/stats/_axis_nan_policy.py:502, in _axis_nan_policy_factory.<locals>.axis_nan_policy_decorator.<locals>.axis_nan_policy_wrapper(***failed resolving arguments***)
500 if sentinel:
501 samples = _remove_sentinel(samples, paired, sentinel)
--> 502 res = hypotest_fun_out(*samples, **kwds)
503 res = result_to_tuple(res)
504 res = _add_reduced_axes(res, reduced_axes, keepdims)
File ~/.local/lib/python3.10/site-packages/scipy/stats/_mannwhitneyu.py:460, in mannwhitneyu(x, y, use_continuity, alternative, axis, method)
249 @_axis_nan_policy_factory(MannwhitneyuResult, n_samples=2)
250 def mannwhitneyu(x, y, use_continuity=True, alternative="two-sided",
251 axis=0, method="auto"):
252 r'''Perform the Mann-Whitney U rank test on two independent samples.
253
254 The Mann-Whitney U test is a nonparametric test of the null hypothesis
(...)
456
457 '''
459 x, y, use_continuity, alternative, axis_int, method = (
--> 460 _mwu_input_validation(x, y, use_continuity, alternative, axis, method))
462 x, y, xy = _broadcast_concatenate(x, y, axis)
464 n1, n2 = x.shape[-1], y.shape[-1]
File ~/.local/lib/python3.10/site-packages/scipy/stats/_mannwhitneyu.py:200, in _mwu_input_validation(x, y, use_continuity, alternative, axis, method)
198 # Would use np.asarray_chkfinite, but infs are OK
199 x, y = np.atleast_1d(x), np.atleast_1d(y)
--> 200 if np.isnan(x).any() or np.isnan(y).any():
201 raise ValueError('`x` and `y` must not contain NaNs.')
202 if np.size(x) == 0 or np.size(y) == 0:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
即使数据帧中没有任何nan
个值,为什么它会产生
错误?