As per my knowledge Python loops are slow, hence it is preferred to use pandas inbuilt functions.
In my problem, one column will have different currencies, I need to convert them to dollar. How can I detect and convert them to dollar using pandas inbuilt functions ?
My column as following:
100Dollar
200Dollar
100Euro
300Euro
184pounds
150pounds
10rupee
30rupee
Note: amount and currency name is in same column.
Note: conversion exchange rate w.r.t dollar {Euro: 1.2, pounds: 1.3, rupee: 0.05}
Note: currency enum is ['Euro', 'Dollar', 'Pounds', 'Rupee']
Use
Series.str.extract
with regular expressions to extra the correct values into a new column. Then map theexchange_rate
to theCurrency
column to calculate theAmount dollars
: