J'essaie de faire des conditions multiples dans un where numpy mais j'obtiens l'erreur : cannot compare a dtyped [object] array with a scalar of type [bool]
Voici la ligne :
d7['CAD'] = np.where(d7['Category'] == 'Stack' & d7['Currency'] == fxratetable['from_currency'],d7['CAD'] * fxratetable['fx_rate'], d7['CAD'])
Tous dtypes
sont object
sauf pour fx_rate qui est float64
.
Une autre idée est que je recherche une valeur avec Category = Stack
mais je cherche des valeurs multiples avec mon Currency = from_currency
.
Quelqu'un peut-il m'aider ?
Gracias.
nouvelle erreur
ValueError: Can only compare identically-labeled Series objects now.
Voici ma nouvelle déclaration
d7['CAD'] = np.where((d7['Category'] == 'Stack') &
(d7['Currency'] == fxratetable['from_currency']),
d7['CAD'] * fxratetable['fx_rate'],
d7['CAD'])
d7 :
+--------------+----------+----------+
| CAD | Currency | Category |
+--------------+----------+----------+
| -4350242.355 | GBP | Stack |
+--------------+----------+----------+
| 424223.7584 | AUD | Stack |
+--------------+----------+----------+
fxratetable :
+---------------+---------+
| from_currency | fx_rate |
+---------------+---------+
| GBP | 1.367 |
+---------------+---------+
| AUD | 0.7706 |
+---------------+---------+
Nouvelle colonne CAO attendue.
+----------------+
| CAD (expected) |
+----------------+
| -5948957.275 |
+----------------+
| 326991.5663 |
+----------------+