0

I'm trying to loop across a list of exchange rate dataframes, to calculate the cross rate and convert them into a different base currency. The code I'm currently running is:

forex_dataframes = [aud_df, eur_df, gbp_df, nzd_df, cny_df, jpy_df]

for i in forex_dataframes:
    if (i == nzd_df).all():
        continue
    else:
        i = nzd_df / i

The calculation should be nzd_df / *currency_df* for every dataframe except nzd_df, as this is already correct.

When I run this code though I'm getting

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

I'm not sure why this is the case as when I print it individually (e.g. (nzd_df == nzd_df).all()) I get a single boolean value back.

Note the forex_dataframes list needs to be in this particular order, but if there is another way of skipping the nzd_df item I'm happy to go with that.

Any help is appreciated, thanks.

Trizzy
  • 45
  • 6
  • "The calculation should be *currency_df* / nzd_df for every dataframe except nzd_df, as this is already correct." Special cases aren't special enough to break the rules. If you need to treat that item differently from the rest of the list, it should be held separately from the list in the first place. – Karl Knechtel Jun 15 '21 at 03:17
  • Anyway, please try to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), and [show the complete traceback](https://meta.stackoverflow.com/questions/359146/why-should-i-post-complete-errors-why-isnt-the-message-itself-enough). – Karl Knechtel Jun 15 '21 at 03:18
  • I think you can not use .all like that, check this https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o – Venkat Jun 15 '21 at 03:20
  • It would be better if you show us what your dfs look like – Prakash Dahal Jun 15 '21 at 08:03

0 Answers0