我目前正在尝试开发一个便利功能,它应该为 pandas 数据框中的每一列创建一个基本图,其中包含数据框中所有列的数据集中的值及其数量。
def plot_value_counts(df, leave_out):
# is supposed to create the subplots grid where I can add the plots
fig, axs = plt.subplots(int(len(df)/2) + 1,int(len(df)/2) + 1)
for idx, name in enumerate(list(df)):
if name == leave_out:
continue
else:
axs[idx] = df[name].value_counts().plot(kind="bar")
return fig, axs
这个片段永远运行,永远不会停止。我尝试查看有关 stackoverflow 的其他类似问题,但找不到任何特定于我的案例的内容。
subplots 函数的使用来自以下问题:Masplotlib 中是否可以自动生成多个子图?
下面是数据文件的一个简短示例,以便大家理解问题: https ://gist.github.com/hentschelpatrick/e0a7e1400a4b5c356ec8b0e4952f8cc1#file-train-csv