嗨喽~大家好呀,这里是魔王呐 ❤ ~!
Jupyter Notebook:
是一个开源的web应用程序,可以使用它来创建和共享包含实时代码、方程、可视化和文本的文档。
Jupyter Notebook是IPython项目的一个派生项目,IPython项目本身曾经有一个IPython Notebook项目。后来从中拆分出去,叫做Jupyter Notebook。
import pandas as pd
import pyecharts.options as opts
from pyecharts.charts import *
from pyecharts.globals import ThemeType#设定主题
from pyecharts.commons.utils import JsCode
df1 = pd.read_csv(r'京东-乐高.csv', engine='python', encoding='utf-8-sig')
df2 = pd.read_csv(r'6K高达.csv', engine='python', encoding='utf-8-sig')
df3 = pd.read_csv(r'6K奥特曼.csv', engine='python', encoding='utf-8-sig')
df1.head(1)
df2.head(1)
df3.head(1)
df_all = pd.concat([df1,df2,df3])
df_all.info()
去除重复值
df_all.drop_duplicates(inplace=True)
删除不必要的列
df_all = df_all.drop(['商品SKU','商品链接','封面图链接','评论链接','店铺链接','页码','当前时间','页面网址'],axis=1)
df_all.head(1)
筛选剔除广告
df_all = df_all[df_all['是否广告'] == '否']
重置索引
df_all = df_all.reset_index(drop=True)
df_all.info()
shopname = df_all.groupby('商家店名')['商品名称'].count().sort_values(ascending=False).head(20)
shopname
绘制商家上线的商品数目Top20柱状图
bar1 = (
Bar(init_opts=opts.InitOpts(theme='dark', width='1000px',height ='500px'))
.add_xaxis(shopname.index.tolist())
.add_yaxis("",shopname.values.tolist())
.set_series_opts(
label_opts=opts.LabelOpts(
is_show=True,
position='insideRight',
font_style='italic'
),
源码、解答、教程+VX:qian97378
itemstyle_opts=opts.ItemStyleOpts(
color=JsCode(
"""new echarts.graphic.LinearGradient(1, 0, 0, 0,
[{offset: 0,color: 'rgb(255,99,71)'}, {offset: 1,color: 'rgb(32,178,170)'}])"""
)
)
)
.set_global_opts(
title_opts=opts.TitleOpts(title="商家上线的商品数目Top20"),
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),
legend_opts=opts.LegendOpts(is_show=True))
.reversal_axis()
)
bar1.render_notebook()
def tranform_price(x):
if x <= 100.0:
return '0~100元'
elif x <= 500.0:
return '101~500元'
elif x <= 2000.0:
return '501~2000元'
elif x <= 5000.0:
return '2001~5000元'
elif x <= 10000.0:
return '5001~10000元'
else:
return '10000以上'
df_all['分级'] = df_all["价格"].apply(lambda x:tranform_price(x))
price_score = df_all['分级'].value_counts()
print(price_score)
datas_pair = [(i, int(j)) for i, j in zip(price_score.index, price_score.values)]
print(datas_pair)
pie1 = (
Pie(init_opts=opts.InitOpts(theme='dark',width='1000px',height='600px'))
.add('', datas_pair, radius=['35%', '60%'])
.set_global_opts(
title_opts=opts.TitleOpts(title='不同价格区间的销售额整体表现'),
legend_opts=opts.LegendOpts(orient='vertical', pos_top='15%', pos_left='2%')
)
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{d}%"))
.set_global_opts(
title_opts=opts.TitleOpts(
# 源码、解答、教程+VX:qian97378
title="乐高、奥特曼、高达\n\n价格区间",
pos_left='center',
pos_top='center',
title_textstyle_opts=opts.TextStyleOpts(
color='#F0F8FF',
font_size=20,
font_weight='bold'
),
)
)
.set_colors(['#EF9050', '#3B7BA9', '#6FB27C', '#FFAF34', '#D8BFD8', '#00BFFF', '#7FFFAA'])
)
pie1.render_notebook()
#单价最高的商品
price_top = df_all.groupby('商品名称')['价格'].sum().sort_values(ascending=False).head(20)
price_top
单价最高的商品详细柱状图
bar=(
Bar(init_opts=opts.InitOpts(height='500px',width='1000px',theme='dark'))
.add_xaxis(price_top.index.tolist())
.add_yaxis(
'单价最高的商品',
price_top.values.tolist(),
label_opts=opts.LabelOpts(is_show=True,position='top'),
itemstyle_opts=opts.ItemStyleOpts(
color=JsCode("""new echarts.graphic.LinearGradient(
0, 0, 0, 1,[{offset: 0,color: 'rgb(255,99,71)'}, {offset: 1,color: 'rgb(32,178,170)'}])
"""
)
)
)
.set_global_opts(
title_opts=opts.TitleOpts(
title='单价最高的商品详细柱状图'),
xaxis_opts=opts.AxisOpts(name='玩具名称',
type_='category',
axislabel_opts=opts.LabelOpts(rotate=90),
),
yaxis_opts=opts.AxisOpts(
name='单价/元',
min_=0,
max_=39980.0,
源码、解答、教程+VX:qian97378
splitline_opts=opts.SplitLineOpts(is_show=True,linestyle_opts=opts.LineStyleOpts(type_='dash'))
),
tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='cross')
)
.set_series_opts(
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_='average',name='均值'),
opts.MarkLineItem(type_='max',name='最大值'),
opts.MarkLineItem(type_='min',name='最小值'),
]
)
)
)
bar.render_notebook()
要成功,先发疯,下定决心往前冲!
学习是需要长期坚持的,一步一个脚印地走向未来!
未来的你一定会感谢今天学习的你。
—— 心灵鸡汤
本文章到这里就结束啦~感兴趣的小伙伴可以复制代码去试试哦