我在下面的代码中可以很好地完成我想要的操作:但是,64000行需要40分钟才能完成.sricpt创建了一个名为PN 3D的新列,该列只接受"部件号"列中的前3个数字
for pn in ro['Part No.']:
ro['PN 3D'] = ro['Part No.'].apply(lambda pn: str(pn)[:3])
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以加速我的程序吗?预先感谢
我有以下数据框:
frame1 = pd.DataFrame(res.items(), columns=['Region', 'Ratio'])
Region Ratio
0 Midwest 0.005669
1 Northeast 0.008920
2 North 0.006374
3 South 0.002904
4 Southeast 0.001928
Run Code Online (Sandbox Code Playgroud)
我现在想要使用带有区域名称的ylabel绘制上面数据框的(hbar),但是,我只得到y标签上的数字(0到4),如下所示:
frame1['Ratio'].plot(y=frame1['Region'], x=frame1['Ratio'], kind="barh", align='center', color='blue')
Run Code Online (Sandbox Code Playgroud)
我如何绘制每个地区的名称?提前致谢
我正在尝试从我创建的绘图中删除空白区域,请参见下图:
可以看到,右侧和底部都有一个大白点,该如何解决?请按照我的脚本执行:
fig = plt.figure(figsize=(7,7))
ax1 = plt.subplot2grid((4,3), (0,0),)
ax2 = plt.subplot2grid((4,3), (1,0),)
ax3 = plt.subplot2grid((4,3), (0,1),)
ax4 = plt.subplot2grid((4,3), (1,1),)
data = self.dframe[i]
tes = print_data(data, self.issues, self.color, self.type_user)
tes.print_top(data=data, top=10, ax=ax1, typegraph="hbar", problem=self.issues[i], tone=self.color[i])
tes.print_top(data=data, top=10, ax=ax2, typegraph="prod_bar", problem=self.issues[i], tone=self.color[i])
tes.print_top(data=data, top=10, ax=ax3, typegraph="reg_hbar", problem=self.issues[i], tone=self.color[i])
tes.print_top(data=data, top=10, ax=ax4, typegraph=self.type_user, problem=self.issues[i], tone=self.color[i])
problem = self.issues[i]
plt.tight_layout()
name = problem + str('.PNG')
plt.close(fig)
fig.savefig(name)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激