Python 是否不打印数据透视表输出?

Python 是否不打印数据透视表输出?,python,pandas,plot,pivot,pivot-table,Python,Pandas,Plot,Pivot,Pivot Table,我有一个带有变量Credit_History(0或1)和Loan_Status(Y或N)的数据框架。Temp1只显示标记为0或1的行数。Temp2是我想将Y或N编码为0或1,然后求平均值的地方 temp1 = df['Credit_History'].value_counts(ascending=True) temp2 = df.pivot_table(values='Loan_Status',index= ['Credit_History'],aggfunc=lambda x: x.map({

我有一个带有变量Credit_History(0或1)和Loan_Status(Y或N)的数据框架。Temp1只显示标记为0或1的行数。Temp2是我想将Y或N编码为0或1,然后求平均值的地方

temp1 = df['Credit_History'].value_counts(ascending=True)
temp2 = df.pivot_table(values='Loan_Status',index=
['Credit_History'],aggfunc=lambda x: x.map({'Y':1,'N':0}).mean())

print ('Frequency Table for Credit History:')
print (temp1)
print ('\nProbility of getting loan for each Credit History class:') 
print (temp2)
当我绘图时,我希望是一个1行乘2列的区域。但它看起来像一个2行2列的区域,包含3个绘图。Temp2打印了两次,但其中一次为空,轴标题除外。我假设我在创建temp2对象时声明了一些错误


考虑布置绘图尺寸,然后将轴指定给绘图:

fig, axs = plt.subplots(nrows = 1, ncols=2, figsize=(12,4))

temp1.plot(kind='bar', title='Applicants by Credit_History', ax=axs[0])             
axs[0].set_xlabel('Credit_History')
axs[0].set_ylabel('Count of Applicants')

temp2.plot(kind = 'bar', title='Probability of getting loan by credit history', ax=axs[1])
axs[1].set_xlabel('Credit_History')
axs[1].set_ylabel('Probability of getting loan')

fig.tight_layout()
plt.show()
plt.clf()
plt.close()
输出(使用随机数据)


考虑布置绘图尺寸,然后为绘图指定轴:

fig, axs = plt.subplots(nrows = 1, ncols=2, figsize=(12,4))

temp1.plot(kind='bar', title='Applicants by Credit_History', ax=axs[0])             
axs[0].set_xlabel('Credit_History')
axs[0].set_ylabel('Count of Applicants')

temp2.plot(kind = 'bar', title='Probability of getting loan by credit history', ax=axs[1])
axs[1].set_xlabel('Credit_History')
axs[1].set_ylabel('Probability of getting loan')

fig.tight_layout()
plt.show()
plt.clf()
plt.close()
输出(使用随机数据)