0
votes

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
1
IIUC: InternalTxns.loc[InternalTxns["type"].isin(["INTERNAL_DEBIT","INTERNAL_TRANSFER_REVERSAL"]),'amount']=InternalTxns['amount']*-1EdChum
Thanks a ton @EdChum for quick response, but i guess it will result in Syntax error at 'amount']=Sudhakar Chavan
Sorry did you execute this line of code?EdChum
appreciate your help. !, Yep, just now, it does give syntax error.Sudhakar Chavan
how about InternalTxns.loc[InternalTxns["type"].isin(["INTERNAL_DEBIT","INTERNAL_TRANSFER‌​_REVERSAL"]),'amount'] *= -1 Also on SO it's common form to post raw data or a link to your data plus your code and desired output rather than imagesEdChum

1 Answers

0
votes

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