You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This simply hasn't been implemented, but otherwise was not intentional. Help would be appreciated if you're interested in putting together a PR. The place to get started (I believe) would be to implement the shift method on CategoricalBlock in pandas.core.internals.
In [2]: s = Series(list('aabbcde'),dtype='category')
In [3]: s
Out[3]:
0 a
1 a
2 b
3 b
4 c
5 d
6 e
dtype: category
Categories (5, object): [a < b < c < d < e]
In [4]: s.values
Out[4]:
[a, a, b, b, c, d, e]
Categories (5, object): [a < b < c < d < e]
In [5]: s.values.codes
Out[5]: array([0, 0, 1, 1, 2, 3, 4], dtype=int8)
In [6]: np.roll(s.values.codes,len(s)-1,axis=0)
Out[6]: array([0, 1, 1, 2, 3, 4, 0], dtype=int8)
In [7]: codes = np.roll(s.values.codes,len(s)-1,axis=0)
In [8]: codes[-1] = -1
In [11]: pd.Categorical(codes,categories=s.values.categories,fastpath=True)
Out[11]:
[a, b, b, c, d, e, NaN]
Categories (5, object): [a, b, c, d, e]
you would use the Block.shift method (and pass the codes to it for the actual shifting), then wrap it back to a catetgorical (their is a method for that too). Should be pretty straightforward.
Not sure if this is intentional, but Series.shift() won't run with categorical dtypes:
The text was updated successfully, but these errors were encountered: