I need some help thinking through this:
I have a dataset with 61K records of services. Each service gets renewed on a specific date, each service also has a cost and that cost amount is billed in one of 10 different currencies.
what I need to do on each service record is to convert each service cost to CAD currency for the date the service was renewed.
when I do this in a small sample dataset with 6 services it takes 3 seconds, but this implies that if I do this on a 61k record dataset it might take over 8 hours, which is way too long (i think I can do that in excel or google sheets way faster, which I don't want to do)
Is there a better way or approach to do this with pandas/python in google colab so it doesn't take that long?
thank you in advance
# setup
import pandas as pd
!pip install forex-python
from forex_python.converter import CurrencyRates
#sample dataset/df
dummy_data = {
'siteid': ['11', '12', '13', '41', '42','51'],
'userid': [0,0,0,0,0,0],
'domain': ['A', 'B', 'C', 'E', 'F', 'G'],
'currency':['MXN', 'CAD', 'USD', 'USD', 'AUD', 'HKD'],
'servicecost': [2.5, 3.3, 1.3, 2.5, 2.5, 2.3],
'date': ['2022-02-04', '2022-03-05', '2022-01-03', '2021-04-06', '2022-12-05', '2022-11-01']
}
df = pd.DataFrame(dummy_data, columns = ['siteid', 'userid', 'domain','currency','servicecost','date'])
#ensure date is in the proper datatype
df['date'] = pd.to_datetime(df['date'],errors='coerce')
#go through df, get the data to do the conversion and populate a new series
def convertServiceCostToCAD(currency,servicecost,date):
return CurrencyRates().convert(currency, 'CAD', servicecost, date)
df['excrate']=list(map(convertServiceCostToCAD, df['currency'], df['servicecost'], df['date']))