Skip to content

itertuples does not work with categorical column in dataframe #7839

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

Closed
has2k1 opened this issue Jul 25, 2014 · 1 comment · Fixed by #7842
Closed

itertuples does not work with categorical column in dataframe #7839

has2k1 opened this issue Jul 25, 2014 · 1 comment · Fixed by #7842
Labels
Bug Categorical Categorical Data Type
Milestone

Comments

@has2k1
Copy link
Contributor

has2k1 commented Jul 25, 2014

Code Snippet

df = pd.DataFrame({"id":[1,2,3,4,5,6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
df['grade'] = pd.Categorical(df['raw_grade'])
for t in df.itertuples(index=False):
    print(t)

Error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-45-182b29164b1a> in <module>()
      1 df = pd.DataFrame({"id":[1,2,3,4,5,6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
      2 df['grade'] = pd.Categorical(df['raw_grade'])
----> 3 for t in df.itertuples(index=False):
      4     print(t)

/home/has2k1/scm/pandas/pandas/core/frame.pyc in itertuples(self, index)
    549         # use integer indexing because of possible duplicate column names
    550         arrays.extend(self.iloc[:, k] for k in range(len(self.columns)))
--> 551         return zip(*arrays)
    552 
    553     if compat.PY3:  # pragma: no cover

TypeError: izip argument #3 must support iteration

This is on master at commit 24b309f.

Edit:
Version string - pandas: 0.14.1-78-g24b309f

@jreback
Copy link
Contributor

jreback commented Jul 25, 2014

good catch....Series.__iter__ not behaving well with dtype category, fixed in #7842 (will be in master shortly)

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

Successfully merging a pull request may close this issue.

2 participants