# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
values = df.Prices * df.Amount

df['Values'] = values.where(df.Action == 'Sell', other=-values)

In [39]: df
Out[39]: 


# + active=""
# '''
#    Prices  Amount Action  Values
# 0       3      57   Sell     171
# 1      89      42   Sell    3738
# 2      45      70    Buy   -3150
# 3       6      43   Sell     258
# 4      60      47   Sell    2820
# 5      19      16    Buy    -304
# 6      56      89   Sell    4984
# 7       3      28    Buy     -84
# 8      56      69   Sell    3864
# 9      90      49    Buy   -4410'''
# -

order_df['Value'] = order_df.apply(lambda row: (row['Prices']*row['Amount']
                                               if row['Action']=='Sell'
                                               else -row['Prices']*row['Amount']),
                                   axis=1)

StarcoderdataJupyterScriptsDedupFiltered