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

GroupBy with Float Index not Plotting #7025

Closed
grundprinzip opened this issue May 2, 2014 · 3 comments · Fixed by #7026
Closed

GroupBy with Float Index not Plotting #7025

grundprinzip opened this issue May 2, 2014 · 3 comments · Fixed by #7026
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Groupby
Milestone

Comments

@grundprinzip
Copy link

I have the following problem: I have a dataset with a float index that I want to group and plot. If I'm using integer indices it works, with floats it doesn't. Here is the minimal example that once works and once not. I'm testing with the current master. Am I doing something wrong?

This code snippet fails:

import pandas as pd
import numpy as np
test = pd.DataFrame({'def': [1,1,1,2,2,2,3,3,3], 'val': np.random.randn(9)}, index=[1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0])
test.groupby('def')['val'].plot()

While this works:

# This Works
test = pd.DataFrame({'def': [1,1,1,2,2,2,3,3,3], 'val': np.random.randn(9)}, index= [1,2,3,1,2,3,1,2,3])
test.groupby('def')['val'].plot()

The error I get is:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-83-e50f1a9b07c6> in <module>()
----> 1 test.groupby('def')['val'].plot()

/Library/Python/2.7/site-packages/pandas-0.13.1_758_g4a67608-py2.7-macosx-10.9-intel.egg/pandas/core/groupby.pyc in __getattr__(self, attr)
    452         if attr in self._internal_names_set:
    453             return object.__getattribute__(self, attr)
--> 454         if attr in self.obj:
    455             return self[attr]
    456 

/Library/Python/2.7/site-packages/pandas-0.13.1_758_g4a67608-py2.7-macosx-10.9-intel.egg/pandas/core/series.pyc in __contains__(self, key)
    379 
    380     def __contains__(self, key):
--> 381         return key in self.index
    382 
    383     # complex

/Library/Python/2.7/site-packages/pandas-0.13.1_758_g4a67608-py2.7-macosx-10.9-intel.egg/pandas/core/index.pyc in __contains__(self, other)
   2042         try:
   2043             # if other is a sequence this throws a ValueError
-> 2044             return np.isnan(other) and self._hasnans
   2045         except ValueError:
   2046             try:

NotImplementedError: Not implemented for this type
@jreback
Copy link
Contributor

jreback commented May 2, 2014

This is a bug,

as a work-around try this:

test.groupby('def')['val'].apply(lambda x: x.plot())

@jreback jreback added this to the 0.14.0 milestone May 2, 2014
@grundprinzip
Copy link
Author

Thank you! This helps.

Should I leave this issue open?

@jreback
Copy link
Contributor

jreback commented May 2, 2014

yes, I just fixed this...will close in a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants