title: Pandas: append row to DataFrame with multiindex in columns
body: <p>I have a DataFrame with a multiindex in the columns and would like to use dictionaries to append new rows.</p>
  
  <p>Let's say that each row in the DataFrame is a city. The columns contains "distance" and "vehicle". And each cell would be the percentage of the population that chooses this vehicle for this distance.</p>
  
  <p>I'm constructing an index like this:</p>
  
  <pre><code>index_tuples=[]
  
  for distance in ["near", "far"]:
      for vehicle in ["bike", "car"]:
          index_tuples.append([distance, vehicle])
  
  index = pd.MultiIndex.from_tuples(index_tuples, names=["distance", "vehicle"])
  </code></pre>
  
  <p>Then I'm creating a dataframe:</p>
  
  <pre><code>dataframe = pd.DataFrame(index=["city"], columns = index)
  </code></pre>
  
  <p>The structure of the dataframe looks good. Although pandas has added Nans as default values ?</p>
  
  <p><a href="https://i.stack.imgur.com/dbEWw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dbEWw.png" alt="layout of the dataframe"></a></p>
  
  <p>Now I would like to set up a dictionary for the new city and add it:</p>
  
  <pre><code>my_home_city = {"near":{"bike":1, "car":0},"far":{"bike":0, "car":1}}
  dataframe["my_home_city"] = my_home_city
  </code></pre>
  
  <p>But this fails:</p>
  
  <blockquote>
    <p>ValueError: Length of values does not match length of index</p>
  </blockquote>
  
  <p>Here is the complete <a href="https://pastebin.com/Qn4Fr4se" rel="nofollow noreferrer">error message</a> (pastebin)</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thank you for all the good answers. I'm afraid I've oversimplified the problem in my example. Actually my index is nested with 3 levels (and it could become more).</p>
  
  <p>So I've accepted the universal answer of converting my dictionary into a list of tuples. This might not be as clean as the other approaches but works for any multiindex setup.</p>