2
I am working on an automation with reports for the results of cryptocurrency/stock buying and selling operations.
I need to convert the positive value of a cell to negative if it is bought (BUY). And when it’s a sale(SELL) transaction I don’t need to change anything. It’s already positive and will remain so.
Below follows the example of the original Dataframe:
The final result for the Amount column between rows 4 and 9 should be a negative value. Therefore, I have to condition the change of the Amount column to the presence of the BUY value in the Side column.
I tried to use the Pandas . Loc function. But I stopped in the conversion operation from the original value to the negative value.
df.loc[df.Side=='BUY','Amount']="aqui preciso inserir a fórmula para multiplicar por -1"
I ran a test by placing a fixed variable and it works. So I only need the right conversion command or use another function.
Ex:
df.loc[df.Side=='BUY','Amount']='negativo'
If one of the answers below solved your problem and there was no doubt left, choose the one you liked the most and mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any questions or would like further clarification, feel free to comment.
– Augusto Vasques