How can I insert currency symbol (like $, €..) under 'Price' column, when I have different currencies in the same column?
data = [['Shampoo', 0.60, 'USD'],
['Soap', 0.19, 'EURO'],
['Pen', 0.1, 'JPY'],
]
df = pd.DataFrame(data, columns = ['Stuff', 'Price', 'Currency'])
df
Create a mapping
dictionary that maps each currency to its corresponding symbol then use Series.map
to map the values in currency
column, then concatenate the mapped column with price
column:
mapping = {'USD': '$', 'EURO': '€', 'JPY': '¥'}
df['Price'] = df['Currency'].map(mapping) + df['Price'].astype(str)
# print(df)
Stuff Price Currency
0 Shampoo $0.6 USD
1 Soap €0.19 EURO
2 Pen ¥0.1 JPY