您好,我有关于网页抓取的建议。如何从刮取的数据打印最大值、最小值和平均值?我也不知道如何将它与tiitle的外观联系起来。最终打印结果如下所示:
BMW - number of offerts: ..., max price:..., min price: ..., average price: ...
我用这些数据创建了一个列表,但我不知道如何对tiitle的外观求和,并从中计算max等值。 这是我的密码:
for car in carList:
title = car.find('a', class_='offer-title__link').text.strip()
price = car.find('span', class_='offer-price__number').text.strip()
lista = [title, price,]
carFile.write(title + ',')
carFile.write(price + ',')
carFile.write('\n')
print( lista)
print(lista.count(title))
carFile.close()
现在我只数了一点点
如果您想分析数据,那么最好将所有数据都放在
pandas.DataFrame
首先将
[title, int(price)]
添加到外部列表data
然后转换成
DataFrame
然后你可以分析它
你甚至可以在
for
循环中运行更多的汽车您甚至可以绘制价格直方图,以查看哪些价格更受欢迎
您甚至可以简单地将数据保存为
csv
或excel
基于先前代码的最小工作代码
它显示直方图,您必须关闭直方图才能看到下一个数据
结果:
相关问题 更多 >
编程相关推荐