首页 > 解决方案 > 如何限制图表上显示的列数

问题描述

我正在使用以下代码(来源** https://www.kaggle.com/amiiiney/price-prediction-regularization-stacking**

def msv1(data, thresh=20, color='black', edgecolor='black', width=15, 
height=3):
   
plt.figure(figsize=(width,height))
percentage=(data.isnull()[:10].mean())*100
percentage.sort_values(ascending=False).plot.bar(color=color, edgecolor=edgecolor)
plt.axhline(y=thresh, color='r', linestyle='-')
plt.title('Missing values percentage per column', fontsize=20, weight='bold' )
plt.text(len(data.isnull().sum()/len(data))/1.7, thresh+12.5, f'Columns with more than 
{thresh}% missing values', fontsize=12, color='crimson',
     ha='left' ,va='top')
plt.text(len(data.isnull().sum()/len(data))/1.7, thresh - 5, f'Columns 
with less than {thresh} 
missing values', fontsize=12, color='green',
     ha='left' ,va='top')
plt.xlabel('Columns', size=15, weight='bold')
plt.ylabel('Missing values percentage')

return plt.show()

msv1(df, 30, color=sns.color_palette('Reds',15))

由于我的数据集有 171 列,如何将图表上的输出限制为仅包含空数据的列?现在它显示 171 列,还有那些没有丢失数据的列。如何修改代码?

标签: pythonmissing-data

解决方案


推荐阅读