0

Hi there this is my code:

When I try to run this I get an error.

df = pd.read_csv(file, sep='|', encoding='latin-1')

arreglox = df[df.columns['id':'date_in':'date_out':'objetive':'comments']].as_matrix()

arregloy = df[df.columns[1]].as_matrix()

Here is the error:

 File "<ipython-input-30-6060fe26b2b1>", line 1
    arreglox = df[df.columns['id':'date_in':'date_out':'objetive':'comments']].as_matrix()
                                       ^
SyntaxError: invalid syntax

please help me, thank u very much

Psidom
  • 209,562
  • 33
  • 339
  • 356
kenny
  • 1

1 Answers1

0

The syntax is wrong, if you want those columns in that order try this:

arreglox = df[['id','date_in','date_out','objetive','comments']].as_matrix()
Julio Daniel Reyes
  • 5,489
  • 1
  • 19
  • 23
  • thank u very much Julio. i try your code but this is the error: --------------------------------------------------------------------------- C:\Users\Anaconda3\lib\site-packages\pandas\core\indexing.py in _convert_to_indexer(self, obj, axis, is_setter) 1229 mask = check == -1 1230 if mask.any(): -> 1231 raise KeyError('%s not in index' % objarr[mask]) 1232 1233 return _values_from_object(indexer) KeyError: "[''id','date_in','date_out','objetive','comments''] not in index" – kenny Oct 19 '17 at 00:25
  • That means your columns have different names than those you specified. Can you post que result of `print(list(df))` just after loading the csv? That will tell you your column names – Julio Daniel Reyes Oct 19 '17 at 00:57