数据分析
注意点:
1.整理数据时会有一些空缺的数据需要将其进行排除:
pos_not_nan = pos.isna() print(pos_not_nan)
结果:
0 False 1 False 2 False 3 False 4 False ... 453 False 454 False 455 False 456 False 457 True
True 为空
方法:
dics = {'PG':0,'SF':0,'PF':0,'SG':0,'C':0} for i in range(len(pos)): if pos_not_nan[i]==False: dics[pos[i]] += 1 print(dics)
2.画图时有一些不会可以查找网站:
例如:https://gallery.pyecharts.org
在网站中找到一些合适的图将其代码复制一下
再将里面的一些参数进行调整成自己用的参数
画饼图、柱状图:
1、划分出5个收入等级
2、绘制出饼图
柱状图:
from pyecharts import options as opts from pyecharts.charts import Bar a = ["0-2000000","2000001-4000000","4000001-6000000","6000001-8000000","8000001-10000000"] b = [0,0,0,0,0] sal = data['Salary'] sal_na = sal.isna() for i in range(len(sal_na)): if sal_na[i] == False: if sal[i] > 0 and sal[i] < 2000000: b[0] += 1 elif sal[i] > 2000001 and sal[i] < 4000000: b[1] += 1 elif sal[i] > 4000001 and sal[i] < 6000000: b[2] += 1 elif sal[i] > 6000001 and sal[i] < 8000000: b[3] += 1 elif sal[i] > 8000001 and sal[i] < 10000000: b[4] += 1 c = ( Bar() .add_xaxis(a) .add_yaxis("分段",b) .set_global_opts( xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)), title_opts=opts.TitleOpts(title="Bar-旋转X轴标签", subtitle="解决标签名字过长的问题"), ) .render("bar_rotate_xaxis_label.html") )
饼图:
from pyecharts import options as opts from pyecharts.charts import Pie from pyecharts.faker import Faker d = 0 f = 0 e = [] for i in range(len(b)): d += b[i] for j in range(len(b)): f = round(b[j]/d*100,2) e.append(f) c = ( Pie() .add( "", [list(z) for z in zip(a, e)], center=["35%", "50%"], ) .set_global_opts( title_opts=opts.TitleOpts(title="Pie-调整位置"), legend_opts=opts.LegendOpts(pos_left="15%"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:({d}%)")) .render("pie_position.html") )