I am using Pandas to read a CSV file, Forex to convert the currency to other currencies and the integer mode (int
) to remove the decimal division, but it gave an error.
Sample CSV:
Item,Price (BRL)
Dining devices,100
Dishwasher,600
Electric shower,200
Fridge,1600
Induction cooktop cooker,1800
Kitchen cabinet,900
Kit pans,200
Microwave,700
And:
import pandas as pd
from forex_python.converter import CurrencyRates
from pandas.io.parsers import read_csv
cc = CurrencyRates()
cad = cc.convert('BRL', 'CAD', 1)
nzd = cc.convert('BRL', 'NZD', 1)
usd = cc.convert('BRL', 'USD', 1)
c = read_csv('data/purchases.csv')
c.loc["Total"] = c.sum()
c["Item"].values[-1] = " "
I replaced round
with int
, as suggested from Python: Remove division decimal:
c["USD"] = int((((c["Price (BRL)"] * usd) / 2) * 2 + 1))
c["CAD"] = int((((c["Price (BRL)"] * cad) / 2) * 2 + 1))
c["NZD"] = int((((c["Price (BRL)"] * nzd) / 2) * 2 + 1))
c
It gave an error:
TypeError: cannot convert the series to <class 'int'>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-c0af80ffd537> in <module>
14 c["Item"].values[-1] = " "
15
---> 16 c["USD"] = int((((c["Price (BRL)"] * usd) / 2) * 2 + 1))
17 c["CAD"] = int((((c["Price (BRL)"] * cad) / 2) * 2 + 1))
18 c["NZD"] = int((((c["Price (BRL)"] * nzd) / 2) * 2 + 1))
~/GitLab/Gustavo/global/.env/lib/python3.9/site-packages/pandas/core/series.py in wrapper(self)
139 if len(self) == 1:
140 return converter(self.iloc[0])
--> 141 raise TypeError(f"cannot convert the series to {converter}")
142
143 wrapper.__name__ = f"__{converter.__name__}__"
TypeError: cannot convert the series to <class 'int'>