Skip to content
New issue

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

filter with like keyword fails when column names contain integers #2464

Closed
aflaxman opened this issue Dec 9, 2012 · 0 comments
Closed

filter with like keyword fails when column names contain integers #2464

aflaxman opened this issue Dec 9, 2012 · 0 comments
Labels
Milestone

Comments

@aflaxman
Copy link
Contributor

aflaxman commented Dec 9, 2012

Here is a small example:

In [58]:
df = pd.DataFrame(0., index=[0,1,2], columns=[0,1,'A','B'])
df.filter(like='A')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in ()
      1 # BUG in pandas: cannot filter with like keyword if columns contain integers and string
      2 df = pd.DataFrame(0., index=[0,1,2], columns=[0,1,'A','B'])
----> 3 df.filter(like='A')

/snfs2/HOME/abie/ENV/lib/python2.7/site-packages/pandas-0.10.0.dev_85b4b11-py2.7-linux-x86_64.egg/pandas/core/frame.pyc in filter(self, items, like, regex)
   2864             return self.reindex(columns=[r for r in items if r in self])
   2865         elif like:
-> 2866             return self.select(lambda x: like in x, axis=1)
   2867         elif regex:
   2868             matcher = re.compile(regex)

/snfs2/HOME/abie/ENV/lib/python2.7/site-packages/pandas-0.10.0.dev_85b4b11-py2.7-linux-x86_64.egg/pandas/core/generic.pyc in select(self, crit, axis)
    318 
    319         if len(axis) > 0:
--> 320             new_axis = axis[np.asarray([crit(label) for label in axis])]
    321         else:
    322             new_axis = axis

/snfs2/HOME/abie/ENV/lib/python2.7/site-packages/pandas-0.10.0.dev_85b4b11-py2.7-linux-x86_64.egg/pandas/core/frame.pyc in (x)
   2864             return self.reindex(columns=[r for r in items if r in self])
   2865         elif like:
-> 2866             return self.select(lambda x: like in x, axis=1)
   2867         elif regex:
   2868             matcher = re.compile(regex)

TypeError: argument of type 'int' is not iterable

This may have a simple solution, by making all of the labels into strings on line 320 of generic.py, I will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants