I write a short program like this:

coding: utf-8

from pandas import DataFrame from string import letters

df = DataFrame( {'a': range(0, 10), 'b': range(10, 20), 'c': range(20, 30)}, index=list(letters[:10]) ) rec = df.ix['A'] rec['a'] = 1 print df

When I run it with ipython, everything is fine!

$ ipython test.py

a b c A 1 10 20 B 1 11 21 C 2 12 22 D 3 13 23 E 4 14 24 F 5 15 25 G 6 16 26 H 7 17 27 I 8 18 28 J 9 19 29

But when I run it just use python,I get this below:

$ python test.py

Traceback (most recent call last): File "test.py", line 9, in rec = df.ix['A'] File "/usr/local/lib/python2.7/dist-packages/pandas-0.16.2-py2.7-linux-x86_64.egg/pandas/core/indexing.py", line 70, in getitem return self._getitem_axis(key, axis=0) File "/usr/local/lib/python2.7/dist-packages/pandas-0.16.2-py2.7-linux-x86_64.egg/pandas/core/indexing.py", line 929, in _getitem_axis return self._get_label(key, axis=axis) File "/usr/local/lib/python2.7/dist-packages/pandas-0.16.2-py2.7-linux-x86_64.egg/pandas/core/indexing.py", line 86, in _get_label return self.obj._xs(label, axis=axis) File "/usr/local/lib/python2.7/dist-packages/pandas-0.16.2-py2.7-linux-x86_64.egg/pandas/core/generic.py", line 1473, in xs loc = self.index.get_loc(key) File "/usr/local/lib/python2.7/dist-packages/pandas-0.16.2-py2.7-linux-x86_64.egg/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) File "pandas/index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas/index.c:3704) File "pandas/hashtable.pyx", line 686, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12280) File "pandas/hashtable.pyx", line 694, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12231) KeyError: 'A'

Why pandas act different when I use just python?

python version = 2.7.6 ipython version = 4.0.0 pandas version = 0.16.2

Comment From: jorisvandenbossche

You will have to try to debug this yourself, but a good start is by putting the print df before the offending line (it is df.ix['A'] that is failing). Further, certainly check it is running the same python (eg put print pandas.__path__ in the script)

I guess this has to do with the string.letters, this returns capital or lowercase letters depending on the locale setting. At least for me, it returns lower case characters, with the result that your example script fails for me as well.

Comment From: xmduhan

@jorisvandenbossche Thank you! It cause by string.letters.