title: KeyError when trying to access a newly assigned column in a pandas dataframe
body: <p>None of the solution on KeyError posts addressed my problem hence this question:</p>
  
  <p>I have the following column in a Pandas DataFrame:</p>
  
  <pre><code>df['EventDate']
  
  0        26-12-2016
  1        23-12-2016
  2        16-12-2016
  3        15-12-2016
  4        11-12-2016
  5        10-12-2016
  6        07-12-2016
  </code></pre>
  
  <p>Now I am trying to split the Date and extract the last four values of the year into another Series by using the below command:</p>
  
  <pre><code>trial=df["EventDate"].str.split("-",2,expand=True)
  </code></pre>
  
  <p>Now using the 3rd index value I am able to get the entire values:</p>
  
  <pre><code>df.year=trial[2]
  </code></pre>
  
  <p>Checking the data type of the year column now:</p>
  
  <pre><code>type(df.year)
  Out[80]: pandas.core.series.Series
  </code></pre>
  
  <p>Yes it is Pandas Series transferred through trial[2] code to df.year</p>
  
  <pre><code>print(trial[2])
  0        2016
  1        2016
  2        2016
  3        2016
  4        2016
  </code></pre>
  
  <p>Now I am trying to Groupby the Year column and that is where I get the error:</p>
  
  <pre><code>yearwise=df.groupby('year')
  
  Traceback (most recent call last):
  
  File "&lt;ipython-input-81-cf39b80933c4&gt;", line 1, in &lt;module&gt;
  yearwise=df.groupby('year')
  
  File "C:\WINPYTH\python-3.5.4.amd64\lib\site-
  packages\pandas\core\generic.py", line 4416, in groupby
  **kwargs)
  
   File "C:\WINPYTH\python-3.5.4.amd64\lib\site-
   packages\pandas\core\groupby.py", line 1699, in groupby
   return klass(obj, by, **kwds)
  
  File "C:\WINPYTH\python-3.5.4.amd64\lib\site-
  packages\pandas\core\groupby.py", line 392, in __init__
  mutated=self.mutated)
  
  File "C:\WINPYTH\python-3.5.4.amd64\lib\site-
  packages\pandas\core\groupby.py", line 2690, in _get_grouper
  raise KeyError(gpr)
  
  KeyError: 'year'
  </code></pre>
  
  <p>Can you please help to resolve this KeyError and get the Groupby value for Year column?</p>
  
  <p>A THOUSAND thanks in advance for your answers.</p>