title: Using Unstack in Python
body: <p>I am trying to unstack a column in python but it isn't quite doing what I am expecting. My table (called df) looks similar to this:</p>
  
  <pre><code>station_id   year     Day1   Day2 
   210018       1916      4        7
                1917      3        9 
   256700       1916     NaN       8
                1917      6        9
  </code></pre>
  
  <p>I want to unstack by year so that all the days from a year per stationn are in one row. The two days from 1916 would then start first followed by the 2 days from 1917 for station 210018 and 256700. </p>
  
  <p>An example would look like this:</p>
  
  <pre><code>station_id            1916       1917
  210018                4   7      3  9 
  256700                NaN  8     6   9   
  </code></pre>
  
  <p>I am trying to use this code:  </p>
  
  <pre><code>df2=df.unstack(level='year')
  df2.columns=df2.columns.swaplevel(0,1)
  df2=df2.sort(axis=1)
  </code></pre>
  
  <p>I get an error that says <code>AttributeError: 'Series' object has no attribute 'columns'</code>.</p>
  
  <p>Any help would be appreciated.</p>