简体   繁体   English

Seaborn FacetGrid 键错误

[英]Seaborn FacetGrid keyerror

My pandas dataframe looks like this我的熊猫数据框看起来像这样

hours Record Result
04      1     Pass
12      2     Fail
04      3     Good
15      4     Warning

I have 500 rows in my dataframe.I want to plot hours on x axis with the number of records on y axis faceted by result.I need 4 graphs each for pass,fail,good and warning condition.I need to find for each hours how many records fall in each result category.我的数据框中有 500 行。我想在 x 轴上绘制小时数,y 轴上的记录数以结果为分面。我需要 4 个图形分别表示通过、失败、良好和警告条件。我需要找到每个小时每个结果类别中有多少记录。

g = sns.FacetGrid(batch_3, row=batch_3['hours'], col=batch_3['Result'], hue=batch_3['Result'])
g.map(plt.plot, 'Stat')

I am getting the following error我收到以下错误

KeyError:'WARNING' 'WARNING' 'GOOD' 'GOOD' 'WARNING' 'WARNING',.....] not in index"

The reason you are getting the KeyError is that you should pass the column name as a string to the FacetGrid parameters, rather than passing the actual column as a series.你得到的原因KeyError是你应该通过列名作为一个字符串FacetGrid参数,而不是传递的实际列作为一个系列。 For example, this would work例如,这将工作

sns.FacetGrid(batch_3, row='hours', hue='Result')

but this would not但这不会

sns.FacetGrid(batch_3, row=batch_3['hours'], hue=batch_3['Result'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM