【问题标题】:Error : len() of unsized object - Wilconox signed-rank test错误:未大小对象的 len() - Wilconox 有符号秩检验
【发布时间】:2020-08-10 02:51:35
【问题描述】:

我正在对数据集运行 Wilconox 符号秩测试,如下所示:

df = {'Year': ['2019','2018','2017', ....], 'Name':{jon, tim, luca,...}, 'SelfPromotion': [1,0,1,...]} 

脚本如下:

import pandas
from scipy.stats import mannwhitneyu

data1 = df['SelfPromotion']=1
data2 = df['SelfPromotion']=0
print(mannwhitneyu(data1, data2))

这给了我以下错误:

TypeError: len() of unsized object

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-e49d9838e5ac> in <module>
      3 data1 = data['SelfPromotion']=1
      4 data2 = data['SelfPromotion']=0
----> 5 print(mannwhitneyu(data11, data22))

~/opt/anaconda3/envs/shityaar/lib/python3.7/site-packages/scipy/stats/stats.py in mannwhitneyu(x, y, use_continuity, alternative)
   6391     x = np.asarray(x)
   6392     y = np.asarray(y)
-> 6393     n1 = len(x)
   6394     n2 = len(y)
   6395     ranked = rankdata(np.concatenate((x, y)))

TypeError: len() of unsized object


通过查看类似的问题,我已经尝试了所有可能的解决方案来解决这个错误,但不幸的是,没有解决方案可以让它发挥作用。我将不胜感激。

【问题讨论】:

    标签: pandas statistics comparison data-science


    【解决方案1】:

    mannwhitneyu 需要 array 之类的参数,而您将整数作为 args 传递,因此失败。

    做这样的事情:

    In [26]: data1 = df['SelfPromotion'] == 1                                                                                                                                                                     
    In [28]: data2 = df['SelfPromotion'] == 0
    
    In [31]: mannwhitneyu(data1, data2)                                                                                                                                                                         
    Out[31]: MannwhitneyuResult(statistic=3.0, pvalue=0.30962837708843105)
    

    【讨论】:

    • 嗨,我遇到了同样的错误,我尝试了您提供的解决方案,但遗憾的是它没有用。请看my question
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 2012-08-02
    • 2015-10-08
    相关资源
    最近更新 更多