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

Cannot index a dataframe with a boolean dataframe #1366

Closed
JWCornV opened this issue May 31, 2012 · 2 comments
Closed

Cannot index a dataframe with a boolean dataframe #1366

JWCornV opened this issue May 31, 2012 · 2 comments

Comments

@JWCornV
Copy link

JWCornV commented May 31, 2012

Sorry if there is a specific reason why this is not supported, but with boolean dataframe indexing, I would expect the following to work:

http://pandas.pydata.org/pandas-docs/dev/indexing.html#indexing-a-dataframe-with-a-boolean-dataframe


In [36]: df_rand = pd.DataFrame(np.random.randn(10,10))

In [37]: df_rand < 0
Out[37]:
       0      1      2      3      4      5      6      7      8      9
0  False  False   True  False   True  False   True  False   True   True
1  False   True   True  False   True  False  False   True  False   True
2   True   True   True  False   True  False  False   True  False  False
3  False  False   True  False   True   True   True  False  False   True
4   True  False  False   True  False  False   True  False  False  False
5  False  False  False  False  False  False  False  False  False  False
6  False   True  False  False   True   True   True  False  False   True
7  False  False  False   True  False  False   True  False   True  False
8   True   True   True  False   True   True   True  False  False  False
9  False  False   True   True   True  False   True   True   True  False

In [38]: df_rand[df_rand < 0] = -0.1

In [39]: df_rand[df_rand < 0] += 0.1
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\Python27\Scripts\<ipython-input-39-6dc58d9235e9> in <module>()
----> 1 df_rand[df_rand < 0] += 0.1

C:\Python27\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key)
   1655             return self._getitem_multilevel(key)
   1656         else:
-> 1657             return self._get_item_cache(key)
   1658
   1659     def _getitem_array(self, key):

C:\Python27\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item)
    479                 from pandas.core.frame import DataFrame
    480                 if isinstance(item, DataFrame):
--> 481                     raise ValueError('Cannot index using (boolean) dataframe')
    482                 raise
    483

ValueError: Cannot index using (boolean) dataframe

In [40]: print pd.__version__
0.8.0b1
@wesm
Copy link
Member

wesm commented May 31, 2012

I have to see if this is possible (it should be theoretically); it wasn't a deliberate choice one way or the other.

@wesm wesm closed this as completed in 2e537fd Jun 2, 2012
@wesm
Copy link
Member

wesm commented Jun 2, 2012

This is implemented in git master now, will be part of next beta or the final 0.8.0 release

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

No branches or pull requests

2 participants