电子商务网站建设项目规划书,网站地图链接怎么做,网页设计课程主要内容,凡科网站怎么做链接头像logo这是我国星巴克门店的位置#xff0c;营业时间等数据。
1.导入需要用的库#xff0c;同时设置绘图时用到的字体#xff0c;同时防止绘图时负号无法正常显示的情况。
import pandas as pd
from pyecharts.charts import Bar,Map,Line,Pie,Geo
from pyecharts import option…
这是我国星巴克门店的位置营业时间等数据。
1.导入需要用的库同时设置绘图时用到的字体同时防止绘图时负号无法正常显示的情况。
import pandas as pd
from pyecharts.charts import Bar,Map,Line,Pie,Geo
from pyecharts import options as opts
import matplotlib.pyplot as pltplt.rcParams[font.family] [sans-serif]
plt.rcParams[font.sans-serif] [SimHei]
plt.rcParams[axes.unicode_minus] False 2.读取数据并且查看数据是否有缺失值等
data pd.read_excel(D:/每周挑战/星巴克门店.xlsx)
data.info()从上面可以看出该数据集中没有缺失值且营业时间属于标成属性但是实际中时间应该是时间类型因此我们将其转换为时间以便于后续的可视化
3.首先先对营业时间进行处理然后对星巴克在我国分布省份进行统计汇总。
data[开始营业时间_1] pd.to_datetime(data[开始营业时间])
data[停止营业时间_1] pd.to_datetime(data[停止营业时间])
data[营业时长] data[停止营业时间_1] - data[开始营业时间_1]
data[营业时长] pd.to_timedelta(data[营业时长])
data[营业时长] data[营业时长].dt.total_seconds()/3600
data data.drop([开始营业时间_1,停止营业时间_1],axis1)
data[营业时长区间] pd.cut(data[营业时长],bins[0,8,10,12,14,16,24],labels[0-8h,8-10h,10-12h,12-14h,14-16h,16-24h])
range_colors [#228be6,#1864ab,#8BC34A,#FFCA28,#FF5722,#D32F2F,#1DFFF5,#FF850E]
province_data data[省份].value_counts().reset_index()
x province_data[index].tolist()
y province_data[省份].tolist()
bar (Bar(init_opts opts.InitOpts(width1000px,height800px)) # 创建一个柱状图设置初始化选项宽和高.add_xaxis(x[::-1]) # 设置X轴数据将其反转 .add_yaxis(,y[::-1],label_opts opts.LabelOpts(positionright)) # 设置y轴数据将其反转同时设置其为值为右侧.reversal_axis() # 反转x轴和y轴.set_global_opts(title_opts opts.TitleOpts(title全国各省星巴克门店数量, # 标题内容pos_top2%, # 标题距离图表顶部的相对位置pos_leftcenter, # 指定了标题距离图表左侧的相对位置这里是图表中心title_textstyle_opts opts.TextStyleOpts(color#FFC0CB,font_size20,font_weightbold # 指定标题文本的颜色字体大小和粗细)),visualmap_opts opts.VisualMapOpts(is_showFalse, # 视觉映射组件是否显示max_600, # 视觉映射组件的最大值dimension0, # 视觉映射组件的维度。为 0 时根据数据的值来映射颜色。orienthorizontal,pos_top20%,pos_left70%,range_colorrange_colors # 设置视觉映射组件的颜色范围),)
)
bar.render_notebook() 上海市星巴克门店最多超过了1000家。 广东省、浙江省、江苏省、北京市以超过500家的门店分列第二至五位。
4.对各省星巴克的占比进行可视化。
pie (Pie().add(series_name,data_pair[list(z) for z in zip(x,y)],radius[30%,50%],label_optsopts.LabelOpts(is_showFalse,positioncenter)).set_global_opts(title_optsopts.TitleOpts(title各省星巴克门店数量占比,pos_top2%,pos_leftcenter),visualmap_optsopts.VisualMapOpts(is_showFalse,range_colorrange_colors,max_600,dimension0),legend_optsopts.LegendOpts(is_showTrue, pos_right2%, pos_top8%,orientvertical) #horizontal水平方向).set_series_opts(label_optsopts.LabelOpts(formatter{b}:{d}%))
)
pie.render_notebook() 5.对各省星巴克的数量进行可视化
map (Map().add(,[list(z) for z in zip(x,y)],maptypechina,is_map_symbol_showFalse).set_series_opts(label_optsopts.LabelOpts(is_showFalse)).set_global_opts(title_optsopts.TitleOpts(title各省星巴克门店分布数量,pos_top2%,pos_leftcenter),visualmap_optsopts.VisualMapOpts(is_showTrue,max_600,dimension0,pos_top80%,pos_left20%,range_colorrange_colors),legend_optsopts.LegendOpts(is_showTrue))
)
map.render_notebook() 6.各省数量的热力图可视化。
data_pair []# 新建一个BMap对象
geo Geo(init_optsopts.InitOpts(themedark))for _, row in data.iterrows():geo.add_coordinate(row[城市], row[经度], row[纬度]) data_pair.append([row[城市], 1])geo (geo.add_schema(maptypechina).add(,data_pair,type_heatmap,symbol_size5).set_series_opts(label_optsopts.LabelOpts(is_showTrue)).set_global_opts(title_optsopts.TitleOpts(title各城市星巴克门店数量分布热力图,pos_top2%,pos_leftcenter),visualmap_opts opts.VisualMapOpts(pos_top60%,pos_left20%),legend_opts opts.LegendOpts(is_showTrue))
)
geo.render_notebook() 7.对营业开始时间进行分析
data[开始营业时间] pd.to_datetime(data[开始营业时间])
time_data data[开始营业时间].value_counts().reset_index().sort_values(byindex, ascendingTrue)
x time_data[index].tolist()
y time_data[开始营业时间].tolist()bar (Bar().add_xaxis(x[::-1]).add_yaxis(,y[::-1]).set_global_opts(title_optsopts.TitleOpts(title开始营业时间分布,pos_top2%,pos_leftcenter),visualmap_optsopts.VisualMapOpts(is_showFalse),legend_optsopts.LegendOpts(is_showTrue, pos_right8%, pos_top8%,orientvertical),)
)
bar.render_notebook() 7.对一天内的营业时间进行可视化分析。
df_duration data[营业时长区间].value_counts()
df_duration_g data.groupby(营业时长区间)[店铺名称].count()
x_data df_duration_g.index.tolist()
y_data df_duration_g.values.tolist()
bar (Bar(init_optsopts.InitOpts(width1000px, height600px)).add_xaxis(x_data).add_yaxis(, y_data).set_global_opts(title_optsopts.TitleOpts(title营业时长区间数量分布,pos_top2%,pos_leftcenter,title_textstyle_optsopts.TextStyleOpts(color#228be6,font_size20)),visualmap_optsopts.VisualMapOpts(is_showFalse,max_2000,orienthorizontal,pos_top70%,pos_left20%,range_colorrange_colors),legend_optsopts.LegendOpts(is_showTrue, pos_right8%, pos_top8%,orientvertical),)
)
bar.render_notebook() 文章转载自: http://www.morning.ftcrt.cn.gov.cn.ftcrt.cn http://www.morning.cjqcx.cn.gov.cn.cjqcx.cn http://www.morning.fpqsd.cn.gov.cn.fpqsd.cn http://www.morning.nrzbq.cn.gov.cn.nrzbq.cn http://www.morning.hpggl.cn.gov.cn.hpggl.cn http://www.morning.zqkr.cn.gov.cn.zqkr.cn http://www.morning.mrfjr.cn.gov.cn.mrfjr.cn http://www.morning.ypcd.cn.gov.cn.ypcd.cn http://www.morning.nwfpl.cn.gov.cn.nwfpl.cn http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn http://www.morning.lynmt.cn.gov.cn.lynmt.cn http://www.morning.ndlww.cn.gov.cn.ndlww.cn http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn http://www.morning.pnljy.cn.gov.cn.pnljy.cn http://www.morning.tyklz.cn.gov.cn.tyklz.cn http://www.morning.fqmbt.cn.gov.cn.fqmbt.cn http://www.morning.mspkz.cn.gov.cn.mspkz.cn http://www.morning.tbnpn.cn.gov.cn.tbnpn.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.srbbh.cn.gov.cn.srbbh.cn http://www.morning.zqxhn.cn.gov.cn.zqxhn.cn http://www.morning.rjcqb.cn.gov.cn.rjcqb.cn http://www.morning.kqrql.cn.gov.cn.kqrql.cn http://www.morning.nrftd.cn.gov.cn.nrftd.cn http://www.morning.txzmy.cn.gov.cn.txzmy.cn http://www.morning.mxgpp.cn.gov.cn.mxgpp.cn http://www.morning.zqnmp.cn.gov.cn.zqnmp.cn http://www.morning.lfdzr.cn.gov.cn.lfdzr.cn http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn http://www.morning.hybmz.cn.gov.cn.hybmz.cn http://www.morning.ggmls.cn.gov.cn.ggmls.cn http://www.morning.lsjtq.cn.gov.cn.lsjtq.cn http://www.morning.qymqh.cn.gov.cn.qymqh.cn http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn http://www.morning.cfrz.cn.gov.cn.cfrz.cn http://www.morning.bqhlp.cn.gov.cn.bqhlp.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.xlbyx.cn.gov.cn.xlbyx.cn http://www.morning.sldrd.cn.gov.cn.sldrd.cn http://www.morning.yqhdy.cn.gov.cn.yqhdy.cn http://www.morning.wgxtz.cn.gov.cn.wgxtz.cn http://www.morning.pswzc.cn.gov.cn.pswzc.cn http://www.morning.ykrkq.cn.gov.cn.ykrkq.cn http://www.morning.jxltk.cn.gov.cn.jxltk.cn http://www.morning.rwqk.cn.gov.cn.rwqk.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.wmnpm.cn.gov.cn.wmnpm.cn http://www.morning.bxqry.cn.gov.cn.bxqry.cn http://www.morning.hylbz.cn.gov.cn.hylbz.cn http://www.morning.tkyry.cn.gov.cn.tkyry.cn http://www.morning.yaqi6.com.gov.cn.yaqi6.com http://www.morning.ksgjy.cn.gov.cn.ksgjy.cn http://www.morning.ypjjh.cn.gov.cn.ypjjh.cn http://www.morning.djgrg.cn.gov.cn.djgrg.cn http://www.morning.klwxh.cn.gov.cn.klwxh.cn http://www.morning.zqzzn.cn.gov.cn.zqzzn.cn http://www.morning.wdjcr.cn.gov.cn.wdjcr.cn http://www.morning.dyght.cn.gov.cn.dyght.cn http://www.morning.qichetc.com.gov.cn.qichetc.com http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.qsbcg.cn.gov.cn.qsbcg.cn http://www.morning.kbqws.cn.gov.cn.kbqws.cn http://www.morning.xhjjs.cn.gov.cn.xhjjs.cn http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn http://www.morning.ytmx.cn.gov.cn.ytmx.cn http://www.morning.rwjfs.cn.gov.cn.rwjfs.cn http://www.morning.gqjwz.cn.gov.cn.gqjwz.cn http://www.morning.mglqf.cn.gov.cn.mglqf.cn http://www.morning.sfdsn.cn.gov.cn.sfdsn.cn http://www.morning.gsjzs.cn.gov.cn.gsjzs.cn http://www.morning.xpfwr.cn.gov.cn.xpfwr.cn http://www.morning.plkrl.cn.gov.cn.plkrl.cn http://www.morning.bgzgq.cn.gov.cn.bgzgq.cn http://www.morning.atoinfo.com.gov.cn.atoinfo.com http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.glbnc.cn.gov.cn.glbnc.cn http://www.morning.sjqpm.cn.gov.cn.sjqpm.cn http://www.morning.qnzpg.cn.gov.cn.qnzpg.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.wgxtz.cn.gov.cn.wgxtz.cn