使用列输入在箱线图上出错

Getting error on boxplot with column input

我有一个包含三列的数据框 - id、热模板和照明密度值。这是数据的示例- dataframe

我想创建 一个按 thermal_template 分组的水平箱线图,类似于此 - desired boxplot layout 除了在 y 轴上它将是各种 thermal_templates 而在 x 轴上它将是 lighting_density。我正在使用此代码:

boxplot = result.boxplot(column='thermal_template', figsize=(18,8), rot = 90)

我遇到错误 - KeyError:“[Index(['thermal_template'], dtype='object')] 的 None 在 [columns] 中”

我已经确认 'thermal_template' 是列标签。

可重现示例的代码:

import pandas as pd
import matplotlib.pyplot as plt

d = {'ID': [1, 2, 3], 'thermal_template': ['Zone A', 'Zone A/B', 'Zone A/B'], 'lighting_density':[0.36, 0.88, 0.74 ]}
df = pd.DataFrame(data=d)
df

boxplot = df.boxplot(column='thermal_template')

同时指定 bycolumn 会使用您的示例数据生成所需的输出:

df.boxplot(by='thermal_template', column='lighting_density')