A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/10409 below:

merge with categoricals does not preserve categories dtype · Issue #10409 · pandas-dev/pandas · GitHub

Skip to content Navigation Menu

Saved searches Use saved searches to filter your results more quickly

Sign up 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 Additional navigation options

BUG: merge with categoricals does not preserve categories dtype #10409

Description

xref #14351

None of the following merge operations retain the category types. Is this expected? How can I keep them?

Merging on a category type:

Consider the following:

A = pd.DataFrame({'X': np.random.choice(['foo', 'bar'],size=(10,)), 
                  'Y': np.random.choice(['one', 'two', 'three'], size=(10,))})
A['X'] = A['X'].astype('category')

B = pd.DataFrame({'X': np.random.choice(['foo', 'bar'],size=(10,)), 
                  'Z': np.random.choice(['jjj', 'kkk', 'sss'], size=(10,))})
B['X'] = B['X'].astype('category')

if I do the merge, we end up with:

> pd.merge(A, B, on='X').dtypes 
X    object
Y    object
Z    object
dtype: object
Merging on a non-category type:
A = pd.DataFrame({'X': np.random.choice(['foo', 'bar'],size=(10,)), 
                  'Y': np.random.choice(['one', 'two', 'three'], size=(10,))})
A['Y'] = A['Y'].astype('category')

B = pd.DataFrame({'X': np.random.choice(['foo', 'bar'],size=(10,)), 
                  'Z': np.random.choice(['jjj', 'kkk', 'sss'], size=(10,))})
B['Z'] = B['Z'].astype('category')

if I do the merge, we end up with:

pd.merge(A, B, on='X').dtypes
X    object
Y    object
Z    object
dtype: object

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4