title: Python pandas, .apply, use multiple returned values
body: <pre><code>in[1]:  
  
  import pandas as pd
  
      def somefunc(input1, input2):
          output1 = 1
          output2 = 2
  
          return [output1, output2]
  
  
  d = {'col1': ['A1', 'B1'], 'col2': ['A2', 'B2']}
  df = pd.DataFrame(data=d)
  
  df[['col3', 'col4']] = df.apply(lambda x: somefunc(x['col1'], x['col2']), 
  axis=1)
  
  print df  
  
  out[1]:  
  
     col1 col2  col3  col4
  0   A1   A2     1     2
  1   B1   B2     1     2
  </code></pre>
  
  <p>somefunc:<br>
  - Gets data from json in url with arguments input1 and input2 and puts it into a 
    new dataframe df2<br>
  - Creates output1, output2 with values from df2<br>
  - Deletes dataframe when output vaiables is calulated to save RAM  </p>
  
  <p>This executes perfectly, but I want to return 3 values which return an error</p>
  
  <pre><code>in[2]:  
  
  import pandas as pd
  
      def somefunc(input1, input2):
          output1 = 1
          output2 = 2  
          output3 = 3
  
  
          return [output1, output2, output3]
  
  
  d = {'col1': ['A1', 'B1'], 'col2': ['A2', 'B2']}
  df = pd.DataFrame(data=d)
  
  df[['col3', 'col4', 'col5']] = df.apply(lambda x: somefunc(x['col1'], x['col2']), 
  axis=1)
  
  print df  
  
  out[2]:  
  "ValueError: Columns must be same length as key"
  </code></pre>
  
  <p>The error is different from my actual program, but I guess it correlates;</p>
  
  <pre><code>KeyError: "['col3' 'col4' 'col5'] not in index"
  </code></pre>
  
  <p>Why does this work with one and two outputs but not three?<br>
  Python 2.7.14</p>