目录
解决问题
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型数据即可!
1. array [[2.1909676502373716 2.607015388816513 1.3860962260762568 ... 2. -1.1294268713572033 2.5030404172865484 '1'] 3. [2.1833913365652493 2.607015388816513 1.3760805967854473 ... 4. -0.7176317548954712 2.4492909440768904 '1'] 5. [2.172026866057066 2.607015388816513 1.3760805967854473 ... 6. -0.6735108495602856 2.180543578028602 '1'] 7. ... 8. [2.172026866057066 2.607015388816513 1.3760805967854473 ... 9. -0.6735108495602856 1.9547957905480406 '1'] 10. [2.1833913365652493 2.607015388816513 1.3760805967854473 ... 11. -0.6735108495602856 2.03004505304156 '1'] 12. [2.172026866057066 2.607015388816513 1.3760805967854473 ... 13. -0.6735108495602856 1.9977953691157657 '1']]
哈哈,大功告成!
文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树绘图库Matplotlib风格和样式81260 人正在系统学习中