我正在尝试编写一个函数,它将数据集x作为参数,其中只有分类特征和相应的数字标签y,并为所有特征并排生成直方图图和小提琴图。问题是出于某种原因,我的函数只生成直方图或小提琴,而忽略了其他的。我就是不明白为什么。
def plotPerColumnDistribution(x,y, nGraphShown, nGraphPerRow):
ds = pd.concat([x, y], axis=1)
nunique = x.nunique()
x = x[[col for col in x if nunique[col] > 1 and nunique[col] < 50]] # For displaying purposes, pick columns that have between 1 and 50 unique values
nRow, nCol = x.shape
columnNames = list(x)
nGraphRow = (nCol + nGraphPerRow - 1) / nGraphPerRow
plt.figure(num = None, figsize = (6 * nGraphPerRow, 8 * nGraphRow), dpi = 80, facecolor = 'w', edgecolor = 'k')
for i in range(min(nCol, nGraphShown)):
plt.subplot(nGraphRow, nGraphPerRow, i + 1)
columnDf = x.iloc[:, i]
columnName = x.columns[i]
if (not np.issubdtype(type(columnDf.iloc[0]), np.number)):
valueCounts = columnDf.value_counts()
sns.histplot(x=columnName, data=ds)
sns.violinplot(x=columnName, y='total_claim_amount', data=ds)
else:
columnDf.hist()
plt.ylabel('counts')
plt.xticks(rotation = 90)
plt.title(f'{columnNames[i]} (column {i})')
plt.tight_layout(pad = 1.0, w_pad = 1.0, h_pad = 1.0)
plt.show()
暂无答案!
目前还没有任何答案,快来回答吧!