#๐ How can i turn a categorical column into a binary one?
18 messages ยท Page 1 of 1 (latest)
@zealous anvil
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
!code
there are a thousand different ways to store tabular data, that screen snippet tells me very little about your code
!code df_test["Gender"] = df_test["Gender"].where(df_test["Gender"] == "Male", 1) df_test["Gender"] = df_test["Gender"].where(df_test["Gender"] == "Female", 0) df_training["Gender"] = df_training["Gender"].where(df_training["Gender"] == "Male", 0) df_training["Gender"] = df_training["Gender"].where(df_training["Gender"] == "Female", 1)
copy the example code in the embed, replace print('hello world!') with yours
is this better?
close, just need py after after the top 3 backticks
anyway, my pandas is pretty rusty but with vectorized operations normally you'd just make a new column that performs a criteria check
I think pandas also has an operation called... factorize?
aye, factorize will automatically enumerate unique values which should work for your operation
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.