0

I have a df as following:

df
          asset      quantity      eurusd_close     usdtusd_close     btcusd_close    xusd_close
datetime     
2018-01-25   eur         5000          1,123         xxx.         xxx.          xxx.
2018-02-12   btc         0,05          xxx.          xxx.         17542         xxx.
2018-02-15   usdt        15000         xxx.          1,001        xxx.          xxx.
2018-09-26   eur         2500          1,321         xxx.         xxx.          xxx.

I'm trying to create new columns df['usd'] which is the quantity value in USD using the value of the xusd_close columns concerned by "asset":

df['usd'] = df['quantity'] * df[f'{df.asset.value}usd_close']`

Doesn't work with df.lookup().

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
Wakuu
  • 13
  • 4
  • Does this answer your question? [Pandas get column value based on row value](https://stackoverflow.com/questions/70089730/pandas-get-column-value-based-on-row-value) – Nick ODell Nov 14 '22 at 22:23
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 15 '22 at 12:20
  • Yes thanks. Unfortunately, the solution returns an error. using a non-tuple sequence for multidimensional indexing is deprecated. – Wakuu Nov 15 '22 at 20:12
  • Instead of using [np.arange(len(df)), idx] who lead to an error I used: df3['USD_quantity'] = df3.reindex(cols, axis=1).to_numpy()[df3.index, idx] * df3['quantity"] – Wakuu Nov 15 '22 at 20:39

0 Answers0