Reputation: 377
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.
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
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