【问题标题】:apply custom plotting function to list of features将自定义绘图功能应用于功能列表
【发布时间】:2021-06-26 09:45:23
【问题描述】:

我创建了一个为给定特征创建指定图的函数:

def barplotter (dataset, feature):
  ax1 = sns.displot(dataset, x =feature,  stat = 'density', discrete = True, color = 'black')
  ax1.set(title=feature, xlabel = "")
  ax2 = sns.displot(dataset, x =feature, col = 'status_group', stat = 'density', discrete = True)
  ax2.set(xlabel = "")
  plt.show()

结果:

barplotter ( raw, "quality_group")

我想将此函数应用于功能列表,而不必为每个功能手动应用它。

我正在考虑使用 for 循环。 首先我创建了一个功能列表:categorical_columns = raw[categorical].columns.tolist()

for item in categorical_columns:
  barplotter(raw, item)

很遗憾,这会导致错误

我在这里做错了什么?

【问题讨论】:

    标签: python function for-loop seaborn


    【解决方案1】:

    好的,以防其他人遇到此错误:

    我的一些功能由混合数据类型组成。我将所有功能都转换为字符串,现在 for 循环可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-17
      • 2017-07-19
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多