title: Inner function with "not enough values to unpack"
body: <p>I have been stuck with an inner function tentative and after a lot of changes, I'm still seeing the same error at the end when I run it.</p>
  
  <p>My function code is as below.</p>
  
  <pre><code>def test(name,df,col='',col2=''):  
  
      format_type = list(df[col]) 
  
      d = {name: pd.DataFrame() for name in format_type}     #create two sub_dataframe 
  
  
      for name, df, col2 in d.items():     #look at one sub_df at the time
  
          df['revenue_share']= (df[col2]/df[col2].sum())*100      #calculate revenue_share of each line
  
          print(df['revenue_share'])
  
  
          def function(df,col3='revenue_share'):      #function to separate the companies within several groups depending on their rev_share
  
              if (df[col3] &lt; 0.5):
                  return 'longtail'
              else:
                  return df['company_name']
  
      df['company_name'] = df.apply(lambda x: function(x[col2],x),axis=1) .       #create a new column with the group name
  
  
      return df
  
  </code></pre>
  
  <p>and the error code when I run <code>test(print,format_company_df,col='format',col2='buyer_spend')</code>  :</p>
  
  <p></p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-42-19c1a2b58a26&gt; in &lt;module&gt;
  ----&gt; 1 test(display,miq,col='format',col2='buyer_spend')
        2 
  
  &lt;ipython-input-41-5380164aff21&gt; in test(name, df, col, col2)
        5     d = {name: pd.DataFrame() for name in format_type} #create two sub_dataframe - filtered by format (display or video)
        6 
  ----&gt; 7     for name, df, col2 in d.items(): #look at display or video df
        8 
        9         df['revenue_share']= (df[col2]/df[col2].sum())*100   #calculate revenue_share of each line
  
  ValueError: not enough values to unpack (expected 3, got 2)
  
  </code></pre>
  
  <p>Thanks a lot for your help!</p>