Uniform currencies
In this exercise and throughout this chapter, you will be working with a retail banking dataset stored in the banking
DataFrame.
The dataset contains data on the amount of money stored in accounts (acct_amount
), their currency (acct_cur
), amount invested (inv_amount
), account opening date (account_opened
), and last transaction date (last_transaction
) that were consolidated from American and European branches.
You are tasked with understanding the average account size and how investments vary by the size of account, however in order to produce this analysis accurately, you first need to unify the currency amount into dollars. The pandas
package has been imported as pd
, and the banking
DataFrame is in your environment.
This exercise is part of the course
Cleaning Data in Python
Exercise instructions
- Find the rows of
acct_cur
inbanking
that are equal to'euro'
and store them in the variableacct_eu
. - Find all the rows of
acct_amount
inbanking
that fit theacct_eu
condition, and convert them to USD by multiplying them with1.1
. - Find all the rows of
acct_cur
inbanking
that fit theacct_eu
condition, set them to'dollar'
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Find values of acct_cur that are equal to 'euro'
acct_eu = banking['____'] == '____'
# Convert acct_amount where it is in euro to dollars
banking.loc[____, '____'] = banking.loc[____, '____'] * ____
# Unify acct_cur column by changing 'euro' values to 'dollar'
banking.loc[____, '____'] = ____
# Assert that only dollar currency remains
assert banking['acct_cur'].unique() == 'dollar'