立即学习:https://edu.youkuaiyun.com/course/play/24797/282226?utm_source=blogtoedu
易车网Rav4车辆销售数据信息
import sqlite3, pygal
conn = sqlite3.connect('carData.db')
c = conn.cursor()
# 车型的销量
# carName = c.execute(
# 'SELECT DISTINCT count( yc.design ) AS count,yc.design FROM yiche_cardata as yc GROUP BY yc.design ORDER BY count ')
# dm = pygal.Pie()
# for sell in carName:
# print(sell[0], sell[1])
# dm.add(sell[1], sell[0])
#
# dm.legend_at_bottom = True
# dm.title = 'Rav4 销售数量数据'
# dm.render_to_file('销售数量数据.svg')
# 卖出最多的市
# carName = c.execute(
# # 'SELECT DISTINCT count( yc.buy_addr ) AS count,yc.buy_addr FROM yiche_cardata as yc GROUP BY yc.buy_addr ORDER BY count ')
# # dm = pygal.Pie()
# # for sell in carName:
# # print(sell[0], sell[1])
# # dm.add(sell[1], sell[0])
# #
# # dm.legend_at_bottom = True
# # dm.title = 'Rav4 销售地区数据'
# # dm.render_to_file('销售地区数据.svg')
# 销售最好的月份
# carName = c.execute(
# 'SELECT DISTINCT count( yc.buy_date ) AS count,yc.buy_date FROM yiche_cardata as yc GROUP BY yc.buy_date ORDER BY count ')
# dm = pygal.Pie()
# for sell in carName:
# print(sell[0], sell[1])
# dm.add(sell[1], sell[0])
#
# dm.legend_at_bottom = True
# dm.title = 'Rav4 销售最好的月份'
# dm.render_to_file('销售最好的月份.svg')
# 每款车型的最低价、市区、时间
carName = c.execute(
'SELECT yc.design,yc.buy_addr,yc.buy_date,yc.real_price,yc.original_price, min(yc.real_price) FROM yiche_cardata as yc GROUP BY yc.design order BY real_price')
dm = pygal.Bar()
design, buy_addr, buy_date, real_price, original_price = [], [], [], [], []
for sell in carName:
print(sell[0], sell[1])
design.append(sell[0] + sell[1] + sell[2] + sell[4])
# buy_addr.append(sell[1])
# buy_date.append(sell[2])
real_price.append(float(sell[3]))
# original_price.append(sell[4])
dm.add('销售价格', real_price)
dm.x_labels = design
dm.x_label_rotation = 45
dm.x_title = '车辆型号'
dm._y_title = '价格(万)'
dm.legend_at_bottom = True
dm.title = 'Rav4 每款车型的最低价'
dm.render_to_file('每款车型的最低价.svg')