im trying to get death column or feature using value from kill and condition from player and opponent. The table will looks like this
| Player | Opponent | Kill |
|---|---|---|
| dicey | OXY | 4 |
| OXY | dicey | 6 |
| Verno | dapr | 5 |
| dapr | Verno | 7 |
and how i turn it into
| Player | Opponent | Kill | Death |
|---|---|---|---|
| dicey | OXY | 4 | 6 |
| OXY | dicey | 6 | 4 |
| Verno | dapr | 5 | 7 |
| dapr | Verno | 7 | 5 |
im expecting to get death by using kill column as for the value from condition each player and opponent
>Solution :
Following code will do it:
import pandas
data_frame = {'Player': ['dicey', 'OXY', 'Verno', 'dapr'],
'Opponent': ['OXY', 'dicey', 'dapr', 'Verno'],
'Kill': [4, 6, 5, 7]}
df = pandas.DataFrame(data_frame)
df['Death'] = df.apply(lambda row: df.loc[(df['Player'] == row['Opponent']) &
(df['Opponent'] == row['Player']), 'Kill'].values[0], axis=1)
print(df)