成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘

 成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: 'str' and 'int'

目录

解决问题

解决思路

解决方法


解决问题

    boxplot(array)
  File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\pyplot.py", line 2848, in boxplot
    zorder=zorder, data=data)
  File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\__init__.py", line 1855, in inner
    return func(ax, *args, **kwargs)
  File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 3557, in boxplot
    labels=labels, autorange=autorange)
  File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\cbook\__init__.py", line 1841, in boxplot_stats
    stats['mean'] = np.mean(x)
  File "<__array_function__ internals>", line 6, in mean
  File "E:\Program Files\Python\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 3373, in mean
    out=out, **kwargs)
  File "E:\Program Files\Python\Python36\lib\site-packages\numpy\core\_methods.py", line 172, in _mean
    ret = ret / rcount
TypeError: unsupported operand type(s) for /: 'str' and 'int'

解决思路

类型错误:不支持/:“str”和“int”的操作数类型

解决方法

通过print(array)发现,array中存在str类型数据,所以,要讲str类型数据去掉或者转为int型数据即可!

array [[2.1909676502373716 2.607015388816513 1.3860962260762568 ...
  -1.1294268713572033 2.5030404172865484 '1']
 [2.1833913365652493 2.607015388816513 1.3760805967854473 ...
  -0.7176317548954712 2.4492909440768904 '1']
 [2.172026866057066 2.607015388816513 1.3760805967854473 ...
  -0.6735108495602856 2.180543578028602 '1']
 ...
 [2.172026866057066 2.607015388816513 1.3760805967854473 ...
  -0.6735108495602856 1.9547957905480406 '1']
 [2.1833913365652493 2.607015388816513 1.3760805967854473 ...
  -0.6735108495602856 2.03004505304156 '1']
 [2.172026866057066 2.607015388816513 1.3760805967854473 ...
  -0.6735108495602856 1.9977953691157657 '1']]

哈哈,大功告成!

猜你喜欢

转载自blog.csdn.net/qq_41185868/article/details/124297401