python - 如何限制图表上显示的列数
问题描述
我正在使用以下代码(来源** 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 列,还有那些没有丢失数据的列。如何修改代码?
解决方案
推荐阅读
- ruby - 改进 Ruby Sequel 模型代码
- css - Bootstrap中带有垂直标题的响应表
- excel - 带有时间和文本字符串的行
- amazon-web-services - AWS 目录服务不使用私有 IP 地址解析 VPC 中的资源
- c++ - 在 Qt Creator 中将 Lua 与 C++ 链接
- debugging - 调试 st.executeUpdate(sql);
- json - 字符串以 TextIOWrapper 的形式出现,而不是使用 ast.literal_eval() 函数的字符串
- java - CountDownTimer 适用于 Android Studio,不适用于设备
- visual-studio - Xamarin 文件加载错误
- shell - 强制 GNU make 使用特定的 shell