title: Split / Explode a column of dictionaries into separate columns with pandas
body: <p>I have data saved in a <code>postgreSQL</code> database. I am querying this data using Python2.7 and turning it into a Pandas DataFrame. However, the last column of this dataframe has a dictionary of values inside it. The DataFrame <code>df</code> looks like this:</p>
  <pre><code>Station ID     Pollutants
  8809           {&quot;a&quot;: &quot;46&quot;, &quot;b&quot;: &quot;3&quot;, &quot;c&quot;: &quot;12&quot;}
  8810           {&quot;a&quot;: &quot;36&quot;, &quot;b&quot;: &quot;5&quot;, &quot;c&quot;: &quot;8&quot;}
  8811           {&quot;b&quot;: &quot;2&quot;, &quot;c&quot;: &quot;7&quot;}
  8812           {&quot;c&quot;: &quot;11&quot;}
  8813           {&quot;a&quot;: &quot;82&quot;, &quot;c&quot;: &quot;15&quot;}
  </code></pre>
  <p>I need to split this column into separate columns, so that the DataFrame `df2 looks like this:</p>
  <pre><code>Station ID     a      b       c
  8809           46     3       12
  8810           36     5       8
  8811           NaN    2       7
  8812           NaN    NaN     11
  8813           82     NaN     15
  </code></pre>
  <p>The major issue I'm having is that the lists are not the same lengths. But <strong>all of the lists only contain up to the same 3 values: 'a', 'b', and 'c'</strong>. And they always appear in the same order ('a' first, 'b' second, 'c' third).</p>
  <p>The following code USED to work and return exactly what I wanted (df2).</p>
  <pre><code>objs = [df, pandas.DataFrame(df['Pollutant Levels'].tolist()).iloc[:, :3]]
  df2 = pandas.concat(objs, axis=1).drop('Pollutant Levels', axis=1)
  print(df2)
  </code></pre>
  <p>I was running this code just last week and it was working fine. But now my code is broken and I get this error from line [4]:</p>
  <pre><code>IndexError: out-of-bounds on slice (end) 
  </code></pre>
  <p>I made no changes to the code but am now getting the error. I feel this is due to my method not being robust or proper.</p>
  <p>Any suggestions or guidance on how to split this column of lists into separate columns would be super appreciated!</p>
  <p>EDIT: I think the <code>.tolist()</code> and .apply methods are not working on my code because it is one Unicode string, i.e.:</p>
  <pre><code>#My data format 
  u{'a': '1', 'b': '2', 'c': '3'}
  
  #and not
  {u'a': '1', u'b': '2', u'c': '3'}
  </code></pre>
  <p>The data is imported from the <code>postgreSQL</code> database in this format. Any help or ideas with this issue? is there a way to convert the Unicode?</p>