The code below breaks on the simplest of lines, where I thought I was just adding a column called 'year' with the constant value of what is in the year variable. My packages are up to date with Anaconda 2.3.
Why is this indexing wrong?
The code:
# -*- coding: utf-8 -*-
import iopro
from pandas import *
for year in xrange(2005,2013):
for month in xrange(1,13):
if year == 2005 and month < 7:
continue
filename = 'SOMEPATH' + str(year) + '_mon'+ str(month) +'.txt'
adapter = iopro.text_adapter(filename,parser='csv',field_names=True,output='dataframe',delimiter='\t')
monthly = adapter[['var1','var2','var3']][:]
monthly['year']=year
The error message is:
Traceback (most recent call last):
File "drugs.py", line 21, in <module>
monthly['year']=year
File "/home/seidav/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 2127, in __setitem__
self._set_item(key, value)
File "/home/seidav/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 2205, in _set_item
NDFrame._set_item(self, key, value)
File "/home/seidav/anaconda/lib/python2.7/site-packages/pandas/core/generic.py", line 1196, in _set_item
self._data.set(key, value)
File "/home/seidav/anaconda/lib/python2.7/site-packages/pandas/core/internals.py", line 2980, in set
loc = self.items.get_loc(item)
File "/home/seidav/anaconda/lib/python2.7/site-packages/pandas/core/index.py", line 1572, in get_loc
return self._engine.get_loc(_values_from_object(key))
File "pandas/index.pyx", line 134, in pandas.index.IndexEngine.get_loc (pandas/index.c:3824)
TypeError: expected string or Unicode object, slice found