gpt4 book ai didi

python - 循环遍历数据框列并绘制所有变量?

转载 作者:太空宇宙 更新时间:2023-11-03 20:11:10 25 4
gpt4 key购买 nike

我有一个包含 35 个变量的列表,想要绘制所有变量的直方图以查看分布类型。

fig, axs = plt.subplots(6, 6)
for i in range(6):
for j in range(6):
for column in X.columns:
axs[i,j] = sns.distplot(X[column], hist=True, kde=True,
bins=int(180/5), color = 'darkblue',
hist_kws={'edgecolor':'black'},
kde_kws={'linewidth': 4})
axs[i,j].set_title(column)

目前它仅打印最后 35 个变量。

最佳答案

这个小改变应该可以解决问题:

fig, axs = plt.subplots(6, 6)
for i in range(6):
for j in range(6):
if (i*6) + j > 33:
break
curr_column = X.columns[(i*6) + j]
sns.distplot(X[curr_column], hist=True, kde=True,
ax=axs[i,j],
bins=int(180/5), color = 'darkblue',
hist_kws={'edgecolor':'black'},
kde_kws={'linewidth': 4})
axs[i,j].set_title(curr_column)

关于python - 循环遍历数据框列并绘制所有变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58707832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com