title: Pandas DataFrame apply() ValueError: too many values to unpack (expected 2)
body: <p>I just started poking around Python and while I am very excited, it seems that I am far from pythonian thinking.</p>
  
  <p>Here is an example of approach, which has word 'suboptimal' all over.
  While this is sufficient for my relatively small dataset, I am wondering how can I write it better way?</p>
  
  <pre><code>import pandas as pd
  from pandas import DataFrame
  
  # create sample log data frame
  lg = pd.DataFrame(['Access violation at address 00A97...',
                     'Try to edit the splines or change...',
                     'Access violation at address 00F2B...',
                     'Please make sure the main electro...'], columns=['lg_msg'])
  
  # define message classification
  err_messages = [['Access violation', 'ACC-VIOL', 'PROG'],
                  ['Please make sure th', 'ELE-NOT-PLACED', 'MOD'],
                  ['Try to edit the splines', 'TRY-EDIT-SPLINES', 'MOD']]                
  
  # lookup code
  def message_code(msg_text):
      for msg in err_messages:
          if msg_text.startswith(msg[0]):
              return msg[1]
      return ''
  
  # lookup type
  def message_type(msg_text):
      for msg in err_messages:
          if msg_text.startswith(msg[0]):
              return msg[2]
      return ''               
  
  lg['msg_code'] = lg['lg_msg'].apply(lambda x:  message_code(x))
  lg['msg_type'] = lg['lg_msg'].apply(lambda x:  message_type(x))
  </code></pre>
  
  <p>I tried creating a single function to calculate log entry code and type at once:</p>
  
  <pre><code>def message_code_type(msg_text):
      for msg in err_messages:
          if msg_text.startswith(msg[0]):
              return (msg[1], msg[2])
      return ('', '')
  
  lg['msg_code'], lg['msg_type'] = lg['lg_msg'].apply(lambda x:  message_code_type(x))
  </code></pre>
  
  <p>but getting: </p>
  
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-18-72f97d857539&gt; in &lt;module&gt;()
  ----&gt; 1 lg['msg_code'], lg['msg_code'] = lg['lg_msg'].apply(lambda x:  message_code_type(x))
  
  ValueError: too many values to unpack (expected 2)
  </code></pre>
  
  <p>Is there any way to not traverse the dataframe twice?</p>
  
  <p>Any feedback will be appreciated.</p>
  
  <pre><code>import sys
  print(sys.version)
  3.5.1 |Anaconda 2.4.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)]
  
  pd.__version__
  '0.17.1'
  </code></pre>