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

Int64Index and pivot_table #678

Closed
dieterv77 opened this issue Jan 24, 2012 · 2 comments
Closed

Int64Index and pivot_table #678

dieterv77 opened this issue Jan 24, 2012 · 2 comments
Labels
Milestone

Comments

@dieterv77
Copy link
Contributor

I found an issue related to having an Int64Index and using pivot_table.

Here's the code that illustrates the problem:

Start code

import itertools
import datetime
import pandas

d = datetime.date.min
data = list(itertools.product(['foo', 'bar'], ['A', 'B', 'C'],['x1', 'x2'],[d + datetime.timedelta(i) for i in xrange(20)], [1.0]))

print data[0]
df = pandas.DataFrame(data)

df2 = pandas.pivot_table(df, values=4, rows=[0,1,3],cols=[2])
print df2.columns

df = df.rename(columns=lambda x: str(x))
df2 = pandas.pivot_table(df, values='4', rows=['0','1','3'],cols=['2'])
print df2.columns

end code

I would expect the columns of the pivoted table to be the same regardless of whether the column index of the original table
is ints or strings. I'm finding that this is not the case.

thanks in advance for looking into it.

@dieterv77
Copy link
Contributor Author

I think i sorted out what the problem is here. pivot_table calls unstack on a DataFrame, passing a level argument. When the argument is an int, then unstack assumes (reasonably so) that this is an index, not a level name.

I tried to hack in a fix in
dieterv77@8e7b69a
I don't know the internals well enough to know if this fix is appropriate, but if someone thinks it is, i can open a pull request.

@wesm
Copy link
Member

wesm commented Jan 24, 2012

hi dieter,

I pushed an upstream fix above. thanks for catching/reporting this

@wesm wesm closed this as completed Jan 24, 2012
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