Plot a graph in python using common values in dictionary
<p>How can I visually represent the common keys when a value is selected. I am creating a form where the user will select a value, say <code>'john'</code>. I want to plot  the common keys'a', 'b' and 'c'. Suggestions on how to approach this problem will be very helpful.</p>

<pre><code>d = {
'a': ['john', 'doe', 'jane'], 
'b': ['james', 'danny', 'john'], 
'C':['john', 'scott', 'jane'],
}
</code></pre>

<p>Solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.plot.bar.html" rel="nofollow"><code>Series.plot.bar</code></a>:</p>

<pre><code>import pandas as pd
import matplotlib.pyplot as plt


df = pd.DataFrame({
'a': ['john', 'doe', 'jane'], 
'b': ['james', 'danny', 'john'], 
'c':['john', 'scott', 'jane'],
})

#get boolean mask by condition
print (df == 'john')
       a      b      c
0   True  False   True
1  False  False  False
2  False   True  False

#sum values True
print ((df == 'john').sum())
a    1
b    1
c    1
dtype: int64

(df == 'john').sum().plot.bar()
plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/d2Eau.png" rel="nofollow"><img src="http://i.stack.imgur.com/d2Eau.png" alt="graph"></a></p>

<p>If need show all data:</p>

<pre><code>df1 = df.apply(pd.value_counts).T
print (df1)
   danny  doe  james  jane  john  scott
a    NaN  1.0    NaN   1.0   1.0    NaN
b    1.0  NaN    1.0   NaN   1.0    NaN
c    NaN  NaN    NaN   1.0   1.0    1.0

df1.plot.bar()
plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/BaJoy.png" rel="nofollow"><img src="http://i.stack.imgur.com/BaJoy.png" alt="graph1"></a></p>

python pandas dictionary matplotlib plot