Sudhakar Chavan
Sudhakar Chavan

Reputation: 377

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

I am new to pandas. I am trying to assign a negative sign to one of the column in data frame with below code. but while i do that i get error as below. I tried with below code

INTERNAL_DEBIT = InternalTxns[InternalTxns['type'].isin(['INTERNAL_DEBIT','INTERNAL'])]

new_amnt = (INTERNAL_DEBIT['amount']*-1)

but i need to assign this negative value to only matching conditions and get entire data. I am looking for simpler and less coding.

I read through other posts for the similar error but most of them are not for similar requirement.

Thanks in advance.

enter image description here

InternalTxns[[InternalTxns["type"] in ["INTERNAL_DEBIT","INTERNAL_TRANSFER_REVERSAL"]],'amount']=InternalTxns[[InternalTxns["type"] in ["INTERNAL_DEBIT","INTERNAL_TRANSFER_REVERSAL"]],'amount']*-1

Upvotes: 0

Views: 695

Answers (1)

EdChum
EdChum

Reputation: 394409

You can use the original mask you used from isin with loc to only overwrite those values:

InternalTxns.loc[InternalTxns["type"].isin(["INTERNAL_DEBIT","INTERNAL_TRANSFER‌​‌​_REVERSAL"]),'amount'] *= -1

Upvotes: 0

Related Questions