I have a dataframe with a “Source”, “Amount” and “Journal Date” column. I want to add a column based on the values of these three columns.
I wrote the function as follows:
<code>def entry_type(source,journal_date,amount_value):
if "Payables" in source:
return "Payables"
elif journal_date.is_month_end and amount_value > 0:
return "Accrual"
elif journal_date.is_month_start and amount_value < 0:
return "Reversal"
else:
return source
</code>
<code>def entry_type(source,journal_date,amount_value):
if "Payables" in source:
return "Payables"
elif journal_date.is_month_end and amount_value > 0:
return "Accrual"
elif journal_date.is_month_start and amount_value < 0:
return "Reversal"
else:
return source
</code>
def entry_type(source,journal_date,amount_value):
if "Payables" in source:
return "Payables"
elif journal_date.is_month_end and amount_value > 0:
return "Accrual"
elif journal_date.is_month_start and amount_value < 0:
return "Reversal"
else:
return source
However, when I call the function as follows I get an error:
<code>df("Entry Type") = df.apply(lambda x: entry_type(x["Source"],x["Journal Date"],x["Amount"]),axis=1)
</code>
<code>df("Entry Type") = df.apply(lambda x: entry_type(x["Source"],x["Journal Date"],x["Amount"]),axis=1)
</code>
df("Entry Type") = df.apply(lambda x: entry_type(x["Source"],x["Journal Date"],x["Amount"]),axis=1)
The error is
<code>SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
</code>
<code>SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
</code>
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
How do I fix this to get this to work?