How to plot one column in different graphs?
<p>I have the following problem. I have this kind of a dataframe:</p>

<pre><code>f = pd.DataFrame([['Meyer', 2], ['Mueller', 4], ['Radisch', math.nan], ['Meyer', 2],['Pavlenko', math.nan]])
</code></pre>

<p>is there an elegant way to split the DataFrame up in several dataframes by the first collumn? So, I would like to get a dataframe where first column = 'MÃ¼ller' and another one for first column = Radisch. </p>

<p>Thanks in advance,</p>

<p>Erik</p>

<p>You can loop by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.unique.html" rel="nofollow"><code>unique</code></a> values of column <code>A</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>

<pre><code>df = pd.DataFrame([['Meyer', 2], ['Mueller', 4], 
                   ['Radisch', np.nan], ['Meyer', 2],
                   ['Pavlenko', np.nan]])
df.columns = list("AB")
print (df)
          A    B
0     Meyer  2.0
1   Mueller  4.0
2   Radisch  NaN
3     Meyer  2.0
4  Pavlenko  NaN

print (df.A.unique())
['Meyer' 'Mueller' 'Radisch' 'Pavlenko']

for x in df.A.unique():
    print(df[df.A == x])

       A    B
0  Meyer  2.0
3  Meyer  2.0
         A    B
1  Mueller  4.0
         A   B
2  Radisch NaN
          A   B
4  Pavlenko NaN
</code></pre>

<p>Then use <code>dict</code> comprehension - get <code>dictionary</code> of <code>DataFrames</code>:</p>

<pre><code>dfs = {x:df[df.A == x].reset_index(drop=True) for x in df.A.unique()}    
print (dfs)
{'Meyer':        A    B
0  Meyer  2.0
1  Meyer  2.0, 'Radisch':          A   B
0  Radisch NaN, 'Mueller':          A    B
0  Mueller  4.0, 'Pavlenko':           A   B
0  Pavlenko NaN}

print (dfs.keys())
dict_keys(['Meyer', 'Radisch', 'Mueller', 'Pavlenko'])

print (dfs['Meyer'])
       A    B
0  Meyer  2.0
1  Meyer  2.0

print (dfs['Pavlenko'])
          A   B
0  Pavlenko NaN
</code></pre>

python pandas dataframe