Making subplots based on specific column in Pandas
<p>I have a pandas data frame that contains polynomial approximations of various functions at given points, with variable degrees to the polynomial approximation.  It is arranged so that the first column is the function name, the second is the x value, then columns 2-5 are the approximations with a polynomial of the corresponding degree.  I would like to make 1 plot for each function showing the convergence of the approximations to that function.  I know one way to do it is to break the data frame into separate data frames based on the first column name, but wanted to know if there was a more elegant way to do it.</p>

<p>Edit for clarification:
So in the data frame, there are two unrelated functions, say a and b.  The second column contains the x values, then third and fourth are functions of x.  So it might look like     </p>

<pre><code>   fnctn  x  y1  y2
0     a  1   2   3
1     a  2   3   2
2     a  3   4   3
3     a  4   3   4
4     a  5   2   3
5     b  1   1   2
6     b  2   4   6
7     b  3   9   12
8     b  4   16  20
9     b  5   25  30
</code></pre>

<p>I would want a plot of y1 and y2 where the first column is <em>a</em> on one plot, and on another plot y1 and y2 where the first column is <em>b</em></p>

<pre><code>import pandas
from matplotlib import pyplot as plt
df = pandas.DataFrame({'fnctn':['a','a','a','b','b','b'],'x':[1,2,3,1,2,3],'y1':[2,3,4,3,2,2],'y2':[3,2,3,4,3,2]})

In [19]: df
Out[19]: 
  fnctn  x  y1  y2
0     a  1   2   3
1     a  2   3   2
2     a  3   4   3
3     b  1   3   4
4     b  2   2   3
5     b  3   2   2

for f in set(df['fnctn']): 
     df[df['fnctn']==f].plot(x='x')
</code></pre>

<p><a href="https://i.stack.imgur.com/Rpkgo.png" rel="nofollow"><img src="https://i.stack.imgur.com/Rpkgo.png" alt="a"></a>
<a href="https://i.stack.imgur.com/dAqiC.png" rel="nofollow"><img src="https://i.stack.imgur.com/dAqiC.png" alt="b"></a></p>

python pandas