Issue
I have a dataframe where one of the columns, "deals" is a TRUE/FALSE boolean. I want to create a new column that populates 1 when the "deals" column is True, and 0 when the "deals" columns is False.
I tried the following code but it's giving me all zeros.
df['madedeal'] = np.where(df['deal']=='True', 1, 0)
Solution
You can simply use astype(int)
which converts True to 1 and False to 0 (no need for np.where
here):
df['madedeal'] = df['deal'].astype(int)
Answered By - user7864386
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.