How to TypeError: unsupported operand type(s) for /: ‘map‘ and ‘int‘

这段代码展示了如何使用Python的numpy和pyplot库来分析评论长度。首先,它计算了评论的平均长度及其标准差。然后,通过创建一个盒图和直方图来可视化这些长度,帮助理解数据分布。修改后的代码将`map`结果转换为列表,以便于后续的可视化操作。
摘要由CSDN通过智能技术生成

Original Code:

# Plot the distribution of Review Lengths
# Summarize review length
print("Review length: ")
result = map(len, X)
print("Mean %.2f words (%f)" % (np.mean(result),np.std(result)))
# plot review length as a boxplot and histogram
pyplot.subplot(121)
pyplot.boxplot(result)
pyplot.subplot(122)
pyplot.hist(result)
pyplot.show()

Modified Code:

# Plot the distribution of Review Lengths
# Summarize review length
print("Review length: ")
result = list(map(len, X))
print("Mean %.2f words (%f)" % (np.mean(result),np.std(result)))
# plot review length as a boxplot and histogram
pyplot.subplot(121)
pyplot.boxplot(result)
pyplot.subplot(122)
pyplot.hist(result)
pyplot.show()

 

Solution :

Use the code result = list(map(len, X)) instead of result = map(len, X)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值