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

Add optional parameter for pd.factorize to handle new categories in categorical data dynamically #56466

Closed
wants to merge 34 commits into from

Conversation

jonathanho168
Copy link

@jonathanho168 jonathanho168 commented Dec 12, 2023

Issue with updating release notes (merge conflict):

Addition:
- Enhanced :func:pandas.factorizeto support an additional parameteroriginal_factorization, allowing users to apply an existing factorization scheme to new data. This feature is useful for maintaining consistent category codes across different datasets (:issue:12509).

Example usage:

original_data = ['a', 'b', 'c', 'c', 'd', 'e']
new_data = ['a', 'd', 'e', 'k']

# Original codes will be 0, 1, 2, 2, 3, 4
original_codes, original_uniques = pd.factorize(original_data)

new_codes, new_uniques = pd.factorize(new_data) # New codes will be 0, 1, 2, 3 given existing implementation
new_codes1, new_uniques1 = pd.factorize(new_data, original_factorization=(original_uniques, original_codes))

# New codes 1 will be 0, 3, 4, 5 to account for the mappings previously generated.

@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. Additionally the issue notes that this is a documentation change and a proposal to add a new argument needs a dedicated issue first before proceeding. Closing

@mroeschke mroeschke closed this Jan 8, 2024
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

Successfully merging this pull request may close these issues.

append a categorical with different categories to the existing
5 participants