We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For some reason pandas isn't liking when I create a column named class and attempt to access with .{columnname} method
I also cannot run a query on the dataframe.
Code:
>>> a = pandas.DataFrame({'class':[0], 'clas1': [1]}) >>> a.clas1 0 1 Name: clas1, dtype: int64 >>> a.class File "<stdin>", line 1 a.class ^ SyntaxError: invalid syntax >>> a.query("clas1==1") clas1 class 0 1 0 >>> a.query("class==0") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.4/site-packages/pandas/core/frame.py", line 1918, in query res = self.eval(expr, **kwargs) File "/usr/lib/python3.4/site-packages/pandas/core/frame.py", line 1970, in eval return _eval(expr, **kwargs) File "/usr/lib/python3.4/site-packages/pandas/computation/eval.py", line 230, in eval truediv=truediv) File "/usr/lib/python3.4/site-packages/pandas/computation/expr.py", line 635, in __init__ self.terms = self.parse() File "/usr/lib/python3.4/site-packages/pandas/computation/expr.py", line 652, in parse return self._visitor.visit(self.expr) File "/usr/lib/python3.4/site-packages/pandas/computation/expr.py", line 310, in visit node = ast.fix_missing_locations(ast.parse(clean)) File "/usr/lib/python3.4/ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "<unknown>", line 1 class ==0 ^ SyntaxError: invalid syntax
Dependencies:
commit: None python: 3.4.3.final.0 python-bits: 64 OS: Linux OS-release: 3.18.6-1-ARCH machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.utf8
pandas: 0.15.2 nose: 1.3.4 Cython: None numpy: 1.9.2 scipy: 0.15.1 statsmodels: None IPython: 3.0.0 sphinx: None patsy: None dateutil: 2.4.1 pytz: 2014.10 bottleneck: 1.0.0 tables: 3.1.1 numexpr: 2.4 matplotlib: 1.4.3 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None httplib2: None apiclient: None rpy2: None sqlalchemy: None pymysql: None psycopg2: None
The text was updated successfully, but these errors were encountered:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
class is not a valid Python identifier as its reserved word
simply use df['class'] which is the canonical method of access
Sorry, something went wrong.
Thanks,
Is this a recent change? I've been using the column name 'class' for months now without any problems
nope been there forever
No branches or pull requests
For some reason pandas isn't liking when I create a column named class and attempt to access with .{columnname} method
I also cannot run a query on the dataframe.
Code:
Dependencies:
INSTALLED VERSIONS
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.18.6-1-ARCH
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.utf8
pandas: 0.15.2
nose: 1.3.4
Cython: None
numpy: 1.9.2
scipy: 0.15.1
statsmodels: None
IPython: 3.0.0
sphinx: None
patsy: None
dateutil: 2.4.1
pytz: 2014.10
bottleneck: 1.0.0
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: None
The text was updated successfully, but these errors were encountered: