1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| grouped = df.groupby('employment_type') employment = grouped['salary'].mean().index.tolist() average_salary = [] for i in employment: remote_group = grouped.get_group(i).loc[:, ['salary', 'remote_ratio']] average_salary.append(remote_group.groupby('remote_ratio')['salary'].mean().tolist())
for i in range(len(average_salary)): if len(average_salary[i]) != 3: average_salary[i].append(0)
bar3d = Bar3D() xaxis = [0,1,2,3] ratio = df.groupby('remote_ratio')['salary'].mean().index.tolist() yaxis = [0,1,2] data = average_salary data = [[xaxis[i], yaxis[j], data[i][j]] for i in range(len(xaxis)) for j in range(len(yaxis))]
( bar3d.add( series_name="", data=data, xaxis3d_opts=opts.Axis3DOpts(type_="category", data=employment, name="employment_type", name_gap=30, is_show=True,grid_3d_index=0,axislabel_opts=opts.LabelOpts(rotate=-30)), yaxis3d_opts=opts.Axis3DOpts(type_="category", data=ratio, name="remote_ratio", name_gap=30,is_show=True,grid_3d_index=0, axislabel_opts=opts.LabelOpts(rotate=-30)), zaxis3d_opts=opts.Axis3DOpts(type_="value", name="salary", name_gap=30,is_show=True,grid_3d_index=0,), grid3d_opts=opts.Grid3DOpts(view_control_alpha=60, view_control_beta=10), ) .set_global_opts( title_opts=opts.TitleOpts(title="the salary of remote_ration and employment_type "), visualmap_opts=opts.VisualMapOpts( max_=800000, range_color=[ "#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#ffffbf", "#fee090", "#fdae61", "#f46d43", "#d73027", "#a50026", ], ) ) )
|