Skip to content

Conversation

@Navaneethan2503
Copy link

np.select function does not work with BooleanDtype Closes#43228
p
LETS US MERGE CHANGES

AFTER CHANGES 👍

df = pd.DataFrame({"col1": list("ABBC"), "col2": list("ZZXY")}).astype("string")
conditions = [
    (df["col2"] == "Z") & (df["col1"] == "A"),
    (df["col2"] == "Z") & (df["col1"] == "B"),
    (df["col1"] == "B"),
]
print((df["col2"] == "Z").dtype) #BooleanDtype
choices = ['yellow', 'blue', 'purple']
df['color'] = np.select(conditions, choices, default='black')

output:
col1 col2   color
0    A    Z  yellow
1    B    Z    blue
2    B    X  purple
3    C    Y   black


@rkern
Copy link
Member

rkern commented Aug 29, 2021

This is a pandas issue that they have indicated is something they need to fix on their side.

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.

2 participants