title: Flatten a column with value of type list while duplicating the other column's value accordingly in Pandas
body: <p>Dear power Pandas experts:</p>
  
  <p>I'm trying to implement a function to flatten a column of a dataframe which has element of type list, I want for each row of the dataframe where the column has element of type list, all columns but the designated column to be flattened will be duplicated, while the designated column will have one of the value in the list. </p>
  
  <p>The following illustrate my requirements:</p>
  
  <pre><code>input = DataFrame({'A': [1, 2], 'B': [['a', 'b'], 'c']})
       A   B
  0    1   [a, b]
  1    2   c
  
  expected = DataFrame({'A': [1, 1, 2], 'B': ['a', 'b', 'c']}, index=[0, 0, 1])
  
       A   B
  0    1   a
  0    1   b
  1    2   c
  </code></pre>
  
  <p>I feel that there might  be an elegant solution/concept for it, but I'm struggling. </p>
  
  <p>Here is my attempt, which does not work yet.</p>
  
  <pre><code>def flattenColumn(df, column):
      '''column is a string of the column's name.
      for each value of the column's element (which might be a list), duplicate the rest of columns at the correspdonding row with the (each) value.
      '''
      def duplicate_if_needed(row):
          return concat([concat([row.drop(column, axis = 1), DataFrame({column: each})], axis = 1) for each in row[column][0]])
      return df.groupby(df.index).transform(duplicate_if_needed)
  </code></pre>
  
  <hr>
  
  <p>In recognition of alko's help, here is my trivial generalization of the solution to deal with more than 2 columns in a dataframe:</p>
  
  <pre><code>def flattenColumn(input, column):
      '''
      column is a string of the column's name.
      for each value of the column's element (which might be a list),
      duplicate the rest of columns at the corresponding row with the (each) value.
      '''
      column_flat = pandas.DataFrame(
          [
              [i, c_flattened]
              for i, y in input[column].apply(list).iteritems()
              for c_flattened in y
          ],
          columns=['I', column]
      )
      column_flat = column_flat.set_index('I')
      return (
          input.drop(column, 1)
               .merge(column_flat, left_index=True, right_index=True)
      )
  </code></pre>
  
  <p>The only limitation at the moment is that the order of columns changed, the column flatten would be at the right most, not in its original position. It should be feasible to fix.</p>