Issue
For example, if house column is "Own" (it is string), than I want to put 1 to tax_home. How can I make code for it?
I tried this code but it doesn't work. Help me
def none(x):
if df1['house'] = "Own":
return df1['tax_home'] = 1
else:
return 0
df1['tax_home1'] = df1['house'].apply(none)
Solution
First I would define a function that is not named none for easier to understand that it is actually a function. Then you have to use the argument in the function now called house
. Then return values based on a proper if statement using ==
.
def set_tax_home(house):
if house == "Own":
return 1
else:
return 0
df1['tax_home'] = df1['house'].apply(set_tax_home)
Answered By - Ingebrigt Nygård
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.