Here's a starting DataFrame:
ipdb> df[["line_amount","modifiedAmount"]]
line_amount modifiedAmount
0 30.00
1 2.88 2.88
2 199.20 199.2
3 -105.00 -104
4 150.00 150
5 75.00
6 -450.00 -450
7 16.13 16.13
8 20.00
9 111.99 111.99
What I want is a new column of data (or really to replace the modifiedAmount column with one) that contains "" in cases where the original modifiedAmount was EITHER:
- already "" OR
- equal to line_amount
I'm having such trouble figuring out how to accomplish what I'd've expected to be very easy!
I can get this:
ipdb> equal_test = df.modifiedAmount == df.line_amount
ipdb> blank_test = df.modifiedAmount == ""
but I can't do this:
ipdb> blank_test and equal_test
*** ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I see this option when I want to apply a scalar result, but I couldn't figure out how to put df into lambda like this:
ipdb> df.modifiedAmount.apply(lambda x: "" if x == df.line_amount else x)
*** NameError: global name 'df' is not defined
Any ideas?
The desired result look like this:
ipdb> df[["line_amount","modifiedAmount"]]
line_amount modifiedAmount
0 30.00
1 2.88
2 199.20
3 -105.00 -104.00
4 150.00
5 75.00
6 -450.00
7 16.13
8 20.00
9 111.99
(yes, ideally I want to cast any remaining values to a float to two decimal places)