0

I want to create loop that automatically outputs one table/chart per index. In this case, I only want one index out of the two below. Further, I don't want to even show the first index in the output... I want that index hidden behind the scenes...

Here's the data:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

table = {'Name': ["Joe", "Joe", "Joe","Jane","Jane"],
        'Stf Sch Vp Area': ["Org2","Org1","Org2","Org1","Org2"],
        'Snapshot': ["Feb 2015","Mar 2015","April 2015","Feb 2016","Feb 2016"],
        'Job Type': ["RBE","RBE","Temp","RBE","Temp"],
        'EE Count' :[1,1,1,1,1]}

df_table = pd.DataFrame(table, columns=['Name', 'Stf Sch Vp Area', 'EE Count', 'Snapshot','Job Type'])

df_table

Here's the table:

pivot_table = pd.pivot_table(df_table, index=['Stf Sch Vp Area', 'Snapshot'], values=['EE Count'], columns='Job Type', aggfunc= [np.sum])

And here's the chart:

pivot_table.plot.bar(figsize=[16,10], stacked=False)

But I don't want to show the Org in the table. Rather, I want to use some type of lambda/loop to automatically output each distinct Org into a new chart. Thus, I'd like an output that would automatically product two charts.

Any thoughts?

June
  • 720
  • 10
  • 22
  • So your `pivot_table()` is working, your problem is only with the `plot`? – Joe T. Boka Jul 24 '16 at 00:49
  • 1
    Hi Christopher, welcome to stackoverflow. Some may chip in to offer advice on your question but I thought it would be helpful to suggest some reading for you first. http://stackoverflow.com/help/mcve. I would definitely suggest making your question more specific. – piRSquared Jul 24 '16 at 00:52
  • Thanks, I re-read the link you sent. I also updated the thread so hopefully this helps. Yes, I can visualize the pivot based on the code, but I want to have individual cuts of the "Stf Sch Vp Area" with the rest of the pivot data. There are like 80, and I don't want to write each out one by one... – June Jul 24 '16 at 05:37
  • 1
    "I didn't include the real data in due to data sensitivity" - so use some synthetic data, no? – Ami Tavory Jul 24 '16 at 05:57
  • [How to make good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – MaxU - stand with Ukraine Jul 24 '16 at 09:36
  • Thanks MaxU, that post was incredibly helpful. I think I got this post in a better place. – June Jul 31 '16 at 07:26

0 Answers0