title: Apply function to pandas dataframe that returns multiple rows
body: <p>I would like to apply a function to a pandas DataFrame that splits some of the rows into two. So for example, I may have this as input:</p>
  
  <pre><code>df = pd.DataFrame([{'one': 3, 'two': 'a'}, {'one': 5, 'two': 'b,c'}], index=['i1', 'i2'])
      one  two
  i1    3    a
  i2    5  b,c
  </code></pre>
  
  <p>And I want something like this as output:</p>
  
  <pre><code>      one  two
  i1      3    a
  i2_0    5    b
  i2_1    5    c
  </code></pre>
  
  <p>My hope was that I could just use apply() on the data frame, calling a function that returns a dataframe with 1 or more rows itself, which would then get merged back together. However, this does not seem to work at all. Here is a test case where I am just trying to duplicate each row:</p>
  
  <pre><code>dfa = df.apply(lambda s: pd.DataFrame([s.to_dict(), s.to_dict()]), axis=1)
      one  two
  i1  one  two
  i2  one  two
  </code></pre>
  
  <p>So if I return a DataFrame, the column names of that DataFrame seem to become the contents of the rows. This is obviously not what I want.</p>
  
  <p>There is another question on here that was solved by using <code>.groupby()</code>, however I don't think this applies to my case since I don't actually want to group by anything.</p>
  
  <p>What is the correct way to do this?</p>