-2

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.

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"
Jayashree
  • 811
  • 3
  • 13
  • 28
  • See [mcve] and [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). You are completely ignoring the `FacetGrid` syntax. – ImportanceOfBeingErnest Oct 13 '17 at 09:26

1 Answers1

1

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. 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'])
joelostblom
  • 43,590
  • 17
  • 150
  • 159