Skip to content

Unable to do calculations with categorical dtypes #21117

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
ahmedsoe opened this issue May 18, 2018 · 1 comment
Closed

Unable to do calculations with categorical dtypes #21117

ahmedsoe opened this issue May 18, 2018 · 1 comment

Comments

@ahmedsoe
Copy link

ahmedsoe commented May 18, 2018

df = pd.DataFrame({'a':[1,2,3,2,1,3,4,5,6,7],
                   'b':[1,2,3,2,1,3,4,5,6,7]})
df['a'] = df['a'].astype('category')
df['a'] * df['b']

Problem description

On pandas v0.20.3, this is possible:

Expected Output

Out[23]: 
0     1
1     4
2     9
3     4
4     1
5     9
6    16
7    25
8    36
9    49
dtype: int64

On v0.23.0, the output is:

TypeError: Series cannot perform the operation *
@jreback
Copy link
Contributor

jreback commented May 19, 2018

this is a deliberate choice as numeric operations on categories do not make sense. if you are using categorizals as a memory savings device then wait for #20899

@jreback jreback closed this as completed May 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants