title: Is it possible to append lists of varying lengths as columns in an empty dataframe?
body: <p>I am trying to create code that takes in a set of letters and outputs the different number of words you can make with them. </p>
  
  <p>Here is my code so far:</p>
  
  <pre class="lang-py prettyprint-override"><code>import itertools as itr
  import requests
  from PyDictionary import PyDictionary
  import pandas as pd
  
  x=list(input("enter letters given:"))
  n=len(x)
  dframe=pd.DataFrame()
  dictionary=PyDictionary()
  for i in range(2,n+1,1):
      combinations=list(itr.combinations_with_replacement(x,i))
      format_combinations=[]
      for letters in combinations:
          format_combinations.append(' '.join(letters))
  
      for idx,word in enumerate(format_combinations):
          word=word.replace(" ","")
          format_combinations[idx]=word
      dframe.loc[i]=format_combinations
  </code></pre>
  
  <p>Ignoring the last line of code, it works fine. </p>
  
  <p>With this code I get the error:</p>
  
  <pre><code>ValueError: cannot set a frame with no defined column
  </code></pre>
  
  <p>So I added columns by changing my <code>dframe</code> to <code>dframe=pd.dataframe(columns=list(range(2,n+1,1)))</code></p>
  
  <p>I then got the following error:</p>
  
  <pre><code>ValueError: cannot set a row with mismatched columns
  </code></pre>
  
  <p>My question is, is it possible to create an empty dataframe then append my format_combination list to it as a column for each iteration. </p>
  
  <p>Right now, I believe the error is coming from the fact that my <code>format_combination</code> list changes length during each iteration, but that's my guess. If someone could explain why I am getting this error and if there is any way to append lists as a column in an empty dataframe. </p>
  
  <p>I am still new to pandas and dataframes and just want to know why I can't create a dataframe this way. So far, the only method I've used is to create a dictionary containing the data and use that to create my dataframe. I don't think I have come across an example where a dataframe was created iteratively before.</p>