title: pandas.apply expand column ValueError: If using all scalar values, you must pass an index
body: <p>I want to apply a function to a DataFrame that returns several columns for each column in the original dataset. The apply function returns a DataFrame with columns and indexes but it still raises the error ValueError: If using all scalar values, you must pass an index.</p>
  <p>I've tried to set the name of the output dataframe, to set the columns as a multiindex and set the index as a multiindex but it doesn't work.</p>
  <p>Example: I have this input dataframe</p>
  <pre><code>df_all_users = pd.DataFrame(
      [[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3],
      ],
      index=[&quot;2020-01-01&quot;, &quot;2020-01-02&quot;, &quot;2020-01-03&quot;],
      columns=[&quot;user_1&quot;, &quot;user_2&quot;, &quot;user_3&quot;])
  
            user_1  user_2    user_3
  2020-01-01     1       2         3
  2020-01-02     1       2         3
  2020-01-03     1       2         3
  </code></pre>
  <p>The apply_function is like this:</p>
  <pre><code>def apply_function(df):
      df_out = pd.DataFrame(index=df.index)
      # these columns are in reality computed used some other functions
      df_out[&quot;column_1&quot;] = df.values  # example: pyod.ocsvm.OCSVM.fit_predict(df.values) 
      df_out[&quot;column_2&quot;] = - df.values  # example: pyod.knn.KNN.fit_predict(df.values)
      
      # these are the things I've tried without working
      df_out.name = df.name
      df_out.columns = pd.MultiIndex.from_tuples([(df.name, column) for column in df_out.columns],
                                                 names=[&quot;user&quot;, &quot;score&quot;])
      df_out.index = pd.MultiIndex.from_tuples([(df.name, idx) for idx in df_out.index],
                                               names=[&quot;user&quot;, &quot;date&quot;])
      print(df_out)
      return df_out
  
  df_all_users.apply(apply_function, axis=0, result_type=&quot;expand&quot;)
  </code></pre>
  <p>Which raises the error:</p>
  <blockquote>
  <p>ValueError: If using all scalar values, you must pass an index</p>
  </blockquote>
  <p>The output that I expect would be like this:</p>
  <pre><code>out_df = pd.DataFrame(
      [[1, 1, 2, 2, 3, 3],
       [1, 1, 2, 2, 3, 3],
       [1, 1, 2, 2, 3, 3],
      ],
      index=[&quot;2020-01-01&quot;, &quot;2020-01-02&quot;, &quot;2020-01-03&quot;],
      columns=pd.MultiIndex.from_tuples([(user, column)
                                         for user in [&quot;user_1&quot;, &quot;user_2&quot;, &quot;user_3&quot;]
                                         for column in [&quot;column_1&quot;, &quot;column_2&quot;]],
                                        names=(&quot;user&quot;, &quot;score&quot;))
  )
  
               user_1           user_2            user_3
             column_1 column_2 column_1 column_2 column_1 column_2
  2020-01-01        1        1        2        2        3        3
  2020-01-02        1        1        2        2        3        3
  2020-01-03        1        1        2        2        3        3
  </code></pre>