import pandas as pd
import numpy as np
df = pd.read_csv('~/test.txt')
list(df.columns.values)
I get the following output :
['time', 'Res_fs1', 'angle1', 'Res_fs2', 'angle2', 'Res_ps1', 'Force1',
'Res_ps2', 'Force2', 'object']
when i try to create a numppy array using Res_fs1,Res_fs2,Res_ps1,Res_ps2
X=np.array(df['Res_fs1','Res_fs2','Res_ps1','Res_ps2'])
I get this error message saying key error although the keys exist:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 1969, in
__getitem__
return self._getitem_column(key)
File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 1976, in
_getitem_column
return self._get_item_cache(key)
File "/usr/lib/python2.7/dist-packages/pandas/core/generic.py", line 1091,
in _get_item_cache
values = self._data.get(item)
File "/usr/lib/python2.7/dist-packages/pandas/core/internals.py", line 3211,
in get
loc = self.items.get_loc(item)
File "/usr/lib/python2.7/dist-packages/pandas/core/index.py", line 1759, in
get_loc
return self._engine.get_loc(key)
File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc
(pandas/index.c:3979)
File "pandas/index.pyx", line 157, in pandas.index.IndexEngine.get_loc
(pandas/index.c:3843)
File "pandas/hashtable.pyx", line 668, in
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12265)
File "pandas/hashtable.pyx", line 676, in
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12216)
KeyError: ('Res_fs1', 'Res_fs2', 'Res_ps1', 'Res_ps2')