I'm trying to datafill 2 new columns from 2 existing columns, based on the value of another column.
The logic is that given a positive amount the buyer and seller should be filled out from the party and cparty fields respectively. If the amount is negative then the situation is reversed and the buyer is the cparty rather than the party, and the seller is the party.
I'm trying to avoid doing something iterative - I can get each component using the expressions below but, but having tried to concatenate these results with concat, +, +=, combine_first, fillna and update, I've drawn a blank over how to merge the results.
Each time they're either been overwritten (I suspect because Pandas matches on the column name, and not position) or I get 2 empty columns.
There must be a nice clean pythonic way to combine the below, or similar?
df[['Buyer', 'Seller']] = df[df.amount > 0][['party', 'cparty']]
df[['Buyer', 'Seller']] = df[df.amount < 0][['cparty', 'party']]