The project we will be working in here consists of euro daily exchange rate for various contries between the years 1999 and 2021 (euro is the official currency in most of countries of the European Union). The objective of this project is to find how the euro exchange rate varies with time between different countries (especially with American dollar). The link to the original data is here Link.
The dataset describes euro daily exchage rates between 1999 and 2021. The dataset contains 5699 rows and 41 columns. The first column contains the date in yyyy-mm-dd format and the rest of 40 columns contain the euro exchage rates of different currencies. Of all the columns, 3 are float type and rest are in string format. Few columns (~ 17) in the dataset have null values.
import pandas as pd
import numpy as np
exchange_rates = pd.read_csv('euro-daily-hist_1999_2020.csv')
exchange_rates.head()
Period\Unit: | [Australian dollar ] | [Bulgarian lev ] | [Brazilian real ] | [Canadian dollar ] | [Swiss franc ] | [Chinese yuan renminbi ] | [Cypriot pound ] | [Czech koruna ] | [Danish krone ] | ... | [Romanian leu ] | [Russian rouble ] | [Swedish krona ] | [Singapore dollar ] | [Slovenian tolar ] | [Slovak koruna ] | [Thai baht ] | [Turkish lira ] | [US dollar ] | [South African rand ] | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2021-01-08 | 1.5758 | 1.9558 | 6.5748 | 1.5543 | 1.0827 | 7.9184 | NaN | 26.163 | 7.4369 | ... | 4.8708 | 90.8000 | 10.0510 | 1.6228 | NaN | NaN | 36.8480 | 9.0146 | 1.2250 | 18.7212 |
1 | 2021-01-07 | 1.5836 | 1.9558 | 6.5172 | 1.5601 | 1.0833 | 7.9392 | NaN | 26.147 | 7.4392 | ... | 4.8712 | 91.2000 | 10.0575 | 1.6253 | NaN | NaN | 36.8590 | 8.9987 | 1.2276 | 18.7919 |
2 | 2021-01-06 | 1.5824 | 1.9558 | 6.5119 | 1.5640 | 1.0821 | 7.9653 | NaN | 26.145 | 7.4393 | ... | 4.8720 | 90.8175 | 10.0653 | 1.6246 | NaN | NaN | 36.9210 | 9.0554 | 1.2338 | 18.5123 |
3 | 2021-01-05 | 1.5927 | 1.9558 | 6.5517 | 1.5651 | 1.0803 | 7.9315 | NaN | 26.227 | 7.4387 | ... | 4.8721 | 91.6715 | 10.0570 | 1.6180 | NaN | NaN | 36.7760 | 9.0694 | 1.2271 | 18.4194 |
4 | 2021-01-04 | 1.5928 | 1.9558 | 6.3241 | 1.5621 | 1.0811 | 7.9484 | NaN | 26.141 | 7.4379 | ... | 4.8713 | 90.3420 | 10.0895 | 1.6198 | NaN | NaN | 36.7280 | 9.0579 | 1.2296 | 17.9214 |
5 rows × 41 columns
exchange_rates.tail()
Period\Unit: | [Australian dollar ] | [Bulgarian lev ] | [Brazilian real ] | [Canadian dollar ] | [Swiss franc ] | [Chinese yuan renminbi ] | [Cypriot pound ] | [Czech koruna ] | [Danish krone ] | ... | [Romanian leu ] | [Russian rouble ] | [Swedish krona ] | [Singapore dollar ] | [Slovenian tolar ] | [Slovak koruna ] | [Thai baht ] | [Turkish lira ] | [US dollar ] | [South African rand ] | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5694 | 1999-01-08 | 1.8406 | NaN | NaN | 1.7643 | 1.6138 | NaN | 0.58187 | 34.938 | 7.4433 | ... | 1.3143 | 27.2075 | 9.1650 | 1.9537 | 188.8400 | 42.560 | 42.5590 | 0.3718 | 1.1659 | 6.7855 |
5695 | 1999-01-07 | 1.8474 | NaN | NaN | 1.7602 | 1.6165 | NaN | 0.58187 | 34.886 | 7.4431 | ... | 1.3092 | 26.9876 | 9.1800 | 1.9436 | 188.8000 | 42.765 | 42.1678 | 0.3701 | 1.1632 | 6.8283 |
5696 | 1999-01-06 | 1.8820 | NaN | NaN | 1.7711 | 1.6116 | NaN | 0.58200 | 34.850 | 7.4452 | ... | 1.3168 | 27.4315 | 9.3050 | 1.9699 | 188.7000 | 42.778 | 42.6949 | 0.3722 | 1.1743 | 6.7307 |
5697 | 1999-01-05 | 1.8944 | NaN | NaN | 1.7965 | 1.6123 | NaN | 0.58230 | 34.917 | 7.4495 | ... | 1.3168 | 26.5876 | 9.4025 | 1.9655 | 188.7750 | 42.848 | 42.5048 | 0.3728 | 1.1790 | 6.7975 |
5698 | 1999-01-04 | 1.9100 | NaN | NaN | 1.8004 | 1.6168 | NaN | 0.58231 | 35.107 | 7.4501 | ... | 1.3111 | 25.2875 | 9.4696 | 1.9554 | 189.0450 | 42.991 | 42.6799 | 0.3723 | 1.1789 | 6.9358 |
5 rows × 41 columns
#look at the details of each column
exchange_rates.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 5699 entries, 0 to 5698 Data columns (total 41 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Period\Unit: 5699 non-null object 1 [Australian dollar ] 5699 non-null object 2 [Bulgarian lev ] 5297 non-null object 3 [Brazilian real ] 5431 non-null object 4 [Canadian dollar ] 5699 non-null object 5 [Swiss franc ] 5699 non-null object 6 [Chinese yuan renminbi ] 5431 non-null object 7 [Cypriot pound ] 2346 non-null object 8 [Czech koruna ] 5699 non-null object 9 [Danish krone ] 5699 non-null object 10 [Estonian kroon ] 3130 non-null object 11 [UK pound sterling ] 5699 non-null object 12 [Greek drachma ] 520 non-null object 13 [Hong Kong dollar ] 5699 non-null object 14 [Croatian kuna ] 5431 non-null object 15 [Hungarian forint ] 5699 non-null object 16 [Indonesian rupiah ] 5699 non-null object 17 [Israeli shekel ] 5431 non-null object 18 [Indian rupee ] 5431 non-null object 19 [Iceland krona ] 3292 non-null float64 20 [Japanese yen ] 5699 non-null object 21 [Korean won ] 5699 non-null object 22 [Lithuanian litas ] 4159 non-null object 23 [Latvian lats ] 3904 non-null object 24 [Maltese lira ] 2346 non-null object 25 [Mexican peso ] 5699 non-null object 26 [Malaysian ringgit ] 5699 non-null object 27 [Norwegian krone ] 5699 non-null object 28 [New Zealand dollar ] 5699 non-null object 29 [Philippine peso ] 5699 non-null object 30 [Polish zloty ] 5699 non-null object 31 [Romanian leu ] 5637 non-null float64 32 [Russian rouble ] 5699 non-null object 33 [Swedish krona ] 5699 non-null object 34 [Singapore dollar ] 5699 non-null object 35 [Slovenian tolar ] 2085 non-null object 36 [Slovak koruna ] 2608 non-null object 37 [Thai baht ] 5699 non-null object 38 [Turkish lira ] 5637 non-null float64 39 [US dollar ] 5699 non-null object 40 [South African rand ] 5699 non-null object dtypes: float64(3), object(38) memory usage: 1.8+ MB
Our first objective is to check the trend between Euro and US Dollars. For this purpose we will begin with cleaning the relevant rows. First we will rename the [US dollar] and Period\Unit columns to US_dollar and Time respectively. Then we will change the Time column data into datetime data type.
exchange_rates.rename(columns={'[US dollar ]':'US_dollar', 'Period\\Unit:':'Time'},inplace=True)
exchange_rates['Time'] = pd.to_datetime(exchange_rates['Time'])
exchange_rates.sort_values('Time', inplace=True)
#reset the index of the dataset
exchange_rates.reset_index(drop=True, inplace=True)
Next we will create a new dataset called euro_to_dollar with just Time and US_dollar columns.
euro_to_dollar = exchange_rates[['Time', 'US_dollar']]
euro_to_dollar
Time | US_dollar | |
---|---|---|
0 | 1999-01-04 | 1.1789 |
1 | 1999-01-05 | 1.1790 |
2 | 1999-01-06 | 1.1743 |
3 | 1999-01-07 | 1.1632 |
4 | 1999-01-08 | 1.1659 |
... | ... | ... |
5694 | 2021-01-04 | 1.2296 |
5695 | 2021-01-05 | 1.2271 |
5696 | 2021-01-06 | 1.2338 |
5697 | 2021-01-07 | 1.2276 |
5698 | 2021-01-08 | 1.2250 |
5699 rows × 2 columns
Now let us look at the US_dollar column closely. We will use Series.value_counts() and check all the values first.
euro_to_dollar['US_dollar'].value_counts()
- 62 1.2276 9 1.1215 8 1.1305 7 1.2713 6 .. 1.4364 1 1.2160 1 1.3431 1 1.1101 1 0.8524 1 Name: US_dollar, Length: 3528, dtype: int64
Here on the first row it is showing '-' as a value. We will drop all the rows with '-' symbol. And then convert the data-type to float.
euro_to_dollar['US_dollar'] = euro_to_dollar.loc[:, 'US_dollar'].str.replace('-','')
euro_to_dollar = euro_to_dollar.loc[euro_to_dollar['US_dollar']!='']
euro_to_dollar['US_dollar'].value_counts()
<ipython-input-7-76a23175a1a3>:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy euro_to_dollar['US_dollar'] = euro_to_dollar.loc[:, 'US_dollar'].str.replace('-','')
1.2276 9 1.1215 8 1.1305 7 1.1218 6 1.0888 6 .. 1.4364 1 1.2160 1 1.3431 1 1.1101 1 0.8524 1 Name: US_dollar, Length: 3527, dtype: int64
euro_to_dollar['US_dollar'].astype(float)
0 1.1789 1 1.1790 2 1.1743 3 1.1632 4 1.1659 ... 5694 1.2296 5695 1.2271 5696 1.2338 5697 1.2276 5698 1.2250 Name: US_dollar, Length: 5637, dtype: float64
above we performed multiple tasks. First we renamed the columns, Period\Unit: to Time and US dollar to US_dollar. Then we changed the Time column to datetime format, sorted the values in ascending form and reset the index. We isolated the above 2 columns and named the DataFrame euro_to_dollar. In the US_dollar column we dropped '-' values and changed the format to float.
The Time column depicts daily variation in the euro. If we plot the Time graph, we will see small wiggles rather than a smooth line. To get rid of these wiggles and to show long-term trends, we can use the rolling mean (moving average). Depending on our objective we can show variations in our graph. We can calculate the rolling mean using pandas.Series.rolling().mean() method. Here if we want to calculate the mean for each day, the value will be the mean between the value of that day and the value of the previous day. For the eighth day the mean between eighth day and the seventh day etc. Here the only exception is the first day, which doesn't have a previous day. Below we will calculate the rolling mean for 30 days (one month) and store it in a new column called rolling_mean.
euro_to_dollar['rolling_mean'] = euro_to_dollar.loc[:,'US_dollar'].rolling(30).mean()
euro_to_dollar
<ipython-input-9-da1c54660525>:2: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy euro_to_dollar['rolling_mean'] = euro_to_dollar.loc[:,'US_dollar'].rolling(30).mean()
Time | US_dollar | rolling_mean | |
---|---|---|---|
0 | 1999-01-04 | 1.1789 | NaN |
1 | 1999-01-05 | 1.1790 | NaN |
2 | 1999-01-06 | 1.1743 | NaN |
3 | 1999-01-07 | 1.1632 | NaN |
4 | 1999-01-08 | 1.1659 | NaN |
... | ... | ... | ... |
5694 | 2021-01-04 | 1.2296 | 1.211170 |
5695 | 2021-01-05 | 1.2271 | 1.212530 |
5696 | 2021-01-06 | 1.2338 | 1.213987 |
5697 | 2021-01-07 | 1.2276 | 1.215357 |
5698 | 2021-01-08 | 1.2250 | 1.216557 |
5637 rows × 3 columns
Above we can see that for first 30 rows of the column rolling_mean has NaN values.
Below we will show how the euro-dollar rate has changed under the last three US presidents:
We will use a line plot for this purpose and style fivethirtyeight.
#import necessary modules
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.style as style
import datetime as dt
style.use('fivethirtyeight')
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1, figsize=(6, 8))
axes = [ax1, ax2, ax3]
for ax in axes:
ax.plot(euro_to_dollar['Time'], euro_to_dollar['rolling_mean'], color='#692a38', alpha=0.1)
ax.set_xticklabels([1999, 2000, 2004, 2008, 2012, 2016, 2020], fontsize=8)
ax.set_yticklabels([0.0, 1.0, 1.2, 1.4, 1.6], fontsize=8)
ax.tick_params(left=0, bottom=0)
for location in ['left', 'right', 'bottom', 'top']:
ax.spines[location].set_visible(False)
ax1.plot(euro_to_dollar['Time'][260:2615], euro_to_dollar['rolling_mean'][260:2615], color='#893fe2', linewidth=2.5)
ax2.plot(euro_to_dollar['Time'][2615:4680], euro_to_dollar['rolling_mean'][2615:4680], color='#ca2e3a', linewidth=2.5)
ax3.plot(euro_to_dollar['Time'][4680:], euro_to_dollar['rolling_mean'][4680:], color='#ff8000', linewidth=2.5)
ax1.text(dt.date(2000, 1,15), 1.02, '$1.013',weight='bold', size=7, alpha=0.7)
ax1.text(dt.date(2008, 4,29), 1.6, '$1.574',weight='bold',size=7, alpha=0.7)
ax1.text(dt.date(2014, 5,8), 1.4, '$1.382',weight='bold',size=7, alpha=0.7)
ax1.text(dt.date(2021, 1,8), 1.2, '$1.216',weight='bold',size=7, alpha=0.7)
ax1.text(dt.date(1999, 1, 4), 1.5, 'George.W.Bush(2001-2009)',size=9,color='#893fe2', weight='bold')
ax2.text(dt.date(1999, 1, 4), 1.5, 'Barack Obama(2009-2017)',size=9,color='#ca2e3a', weight='bold')
ax3.text(dt.date(1999, 1, 4), 1.5, 'Donald Trump(2017-2021)',size=9, color='#ff8000', weight='bold')
ax.text(-0.04,3.6, 'Average Exchange Rates from Euro to US Dollar under the \nlast three US presidents',transform=ax.transAxes, size=12, weight='bold')
ax.text(-0.04, 3.5, 'Average exchange rate is ~ $1.19 per euro', transform=ax.transAxes, size=10, weight='bold')
ax.text(-0.04, -0.2, '@DATAQUEST'+' '*69+'Source:European Central Bank', transform=ax.transAxes, color='#f0f0f0', backgroundcolor='#4d4d4d', size=9)
plt.show()
Above graph shows the average exchange rates between euro and US dollars during the ruling of last three US presidents. We used three rows for three presidents and highlighted their tenure in the respective rows labelling thier names. The x-axis is the Time (in years) and y-axis is the exchange rate (in dollars). During Bush's tenure the exchange rate which was at $1.013 in the year 2000, fell initially then rose gradually to $1.574 in the year 2008. Later it kept on fluctuating with slight decrease in the rate and reached $1.382 in the year 2014 during Obama's tenure. Then there is a sudden decrease. After the year 2016 there is a steady fluctuation and the value reached $1.216 by the end of Trumps tenure.
In this section we are going to analyze the exchange rates between euro and Indian Rupee in a similar way we analysed the US Dollars. First we will rename the Indian rupee column to snakecase. Then we will check the count of each value in the rupee column in order see if there are any other values than the numeric ones.
exchange_rates.rename(columns={'[Indian rupee ]':'Indian_rupee'},inplace=True)
euro_indian_rupee = exchange_rates[['Time', 'Indian_rupee']]
euro_indian_rupee
Time | Indian_rupee | |
---|---|---|
0 | 1999-01-04 | NaN |
1 | 1999-01-05 | NaN |
2 | 1999-01-06 | NaN |
3 | 1999-01-07 | NaN |
4 | 1999-01-08 | NaN |
... | ... | ... |
5694 | 2021-01-04 | 89.7890 |
5695 | 2021-01-05 | 89.8670 |
5696 | 2021-01-06 | 90.2040 |
5697 | 2021-01-07 | 90.0455 |
5698 | 2021-01-08 | 89.7975 |
5699 rows × 2 columns
#apply Series.value_counts() method to rupee column in order to look at the value counts
euro_indian_rupee['Indian_rupee'].value_counts()
- 61 68.7743 3 85.0840 3 57.7250 3 58.0010 3 .. 84.8530 1 51.2620 1 43.6920 1 73.9755 1 85.5560 1 Name: Indian_rupee, Length: 5133, dtype: int64
Here again we observe '-' (hyphen) as a value. We will drop this from the column Indian_rupee and change the data-type to float.
euro_indian_rupee['Indian_rupee'] = euro_indian_rupee.loc[:, 'Indian_rupee'].str.replace('-','')
euro_indian_rupee = euro_indian_rupee.loc[euro_indian_rupee['Indian_rupee']!='']
euro_indian_rupee['Indian_rupee'].astype(float)
euro_indian_rupee['Indian_rupee'].value_counts()
<ipython-input-14-5f9e564adcc6>:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy euro_indian_rupee['Indian_rupee'] = euro_indian_rupee.loc[:, 'Indian_rupee'].str.replace('-','')
54.0450 3 64.5950 3 57.7250 3 58.0010 3 56.5980 3 .. 51.2620 1 43.6920 1 73.9755 1 70.3382 1 85.5560 1 Name: Indian_rupee, Length: 5132, dtype: int64
We have succesfully dropped the value '-'. Next we will calculate the rolling mean for the rupee taking average for 30 days and store the values in a new column called rolling_mean.
euro_indian_rupee['rolling_mean'] = euro_indian_rupee.loc[:,'Indian_rupee'].rolling(30).mean()
euro_indian_rupee
<ipython-input-15-bdd0f2bc6052>:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy euro_indian_rupee['rolling_mean'] = euro_indian_rupee.loc[:,'Indian_rupee'].rolling(30).mean()
Time | Indian_rupee | rolling_mean | |
---|---|---|---|
0 | 1999-01-04 | NaN | NaN |
1 | 1999-01-05 | NaN | NaN |
2 | 1999-01-06 | NaN | NaN |
3 | 1999-01-07 | NaN | NaN |
4 | 1999-01-08 | NaN | NaN |
... | ... | ... | ... |
5694 | 2021-01-04 | 89.7890 | 89.262363 |
5695 | 2021-01-05 | 89.8670 | 89.326563 |
5696 | 2021-01-06 | 90.2040 | 89.396563 |
5697 | 2021-01-07 | 90.0455 | 89.467930 |
5698 | 2021-01-08 | 89.7975 | 89.532713 |
5638 rows × 3 columns
Now We will use the dataset euro_indian_rupee and make a line plot using matplotlib style bmh and study the graph. We will segregate the data from 1999 to 2021 into three parts as follows.
These are the 3 ruling parties from 1999 till 2021.
style.use('bmh')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(9, 3))
ax.plot(euro_indian_rupee['Time'], euro_indian_rupee['rolling_mean'], alpha=0.2)
ax.tick_params(left=0,bottom=0)
for location in ['left', 'right', 'bottom', 'top']:
ax.spines[location].set_visible(False)
ax.plot(euro_indian_rupee['Time'][0:1380], euro_indian_rupee['rolling_mean'][0:1380], color='#68aa55')
ax.plot(euro_indian_rupee['Time'][1380:3940], euro_indian_rupee['rolling_mean'][1380:3940], color='#e9887c')
ax.plot(euro_indian_rupee['Time'][3940:], euro_indian_rupee['rolling_mean'][3940:], color='#73d5bc')
ax.set_xticklabels(['', 2000, 2004, 2008, 2012, 2016, 2020], fontsize=10, weight='bold')
ax.set_yticklabels(['',40, 50, 60, 70, 80, 90], fontsize=10, weight='bold')
ax.text(-0.04,1.1, "Average Exchange Rates from Euro to Indian Rupee between 1999 and 2021",transform=ax.transAxes, size=13, weight='bold')
ax.text(-0.04,1, "Average Exchange Rate is ~ \u20B964.52 per euro", transform=ax.transAxes, size=11, weight='bold')
plt.show()
style.use('bmh')
fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(9, 3))
axes = [ax1, ax2, ax3]
for location in ['left', 'right', 'bottom', 'top']:
ax1.spines[location].set_visible(False)
ax2.spines[location].set_visible(False)
ax3.spines[location].set_visible(False)
ax1.plot(euro_indian_rupee['Time'][0:1380], euro_indian_rupee['rolling_mean'][0:1380], color='#68aa55', linewidth=2.5)
ax1.set_xlim(dt.date(2000,1,4), dt.date(2004,4,19))
ax1.set_xticks([dt.date(2000,1,4), dt.date(2001,1,4), dt.date(2002,1,4), dt.date(2003,1,4), dt.date(2004,1,4)])
ax1.set_ylim(35, 60)
ax1.set_yticks([35,40,45,50,55,60])
ax1.set_xticklabels([2000,2001,2002,2003,2004],fontsize=8, weight='bold')
ax1.set_yticklabels(['',40, 45, 50, 55, 60], fontsize=8, weight='bold')
ax1.tick_params(left=0, bottom=0)
ax2.plot(euro_indian_rupee['Time'][1380:3940], euro_indian_rupee['rolling_mean'][1380:3940], color='#e9887c', linewidth=2.5)
ax2.set_xlim(dt.date(2004,4,20), dt.date(2014,4,21))
ax2.set_xticks([dt.date(2004,4,20), dt.date(2006,4,19), dt.date(2008,4,19), dt.date(2010,4,19), dt.date(2012,4,19), dt.date(2014,4,19)])
ax2.set_xticklabels([2004,2006,2008,2010,2012, 2014], fontsize=8, weight='bold')
ax2.set_ylim(50,90)
ax2.set_yticks([50,60,70,80,90])
ax2.set_yticklabels(['', 60, 70, 80, 90], fontsize=8, weight='bold')
ax2.tick_params(left=0, bottom=0, which='major', labelsize=8)
ax3.plot(euro_indian_rupee['Time'][3940:], euro_indian_rupee['rolling_mean'][3940:], color='#73d5bc', linewidth=2.5)
ax3.set_xlim(dt.date(2014,4,20), dt.date(2021,1,8))
ax3.set_xticks([dt.date(2014,4,20),dt.date(2015,4,20), dt.date(2016,4,20),dt.date(2017,4,20), dt.date(2018,4,20), dt.date(2019,4,20), dt.date(2020,4,8), dt.date(2021,1,8)])
ax3.set_xticklabels([2014,2015, 2016,2017, 2018,2019, 2020], fontsize=8, weight='bold')
ax3.set_ylim(65, 90)
ax3.set_yticks([65,70,75,80,85,90])
ax3.set_yticklabels(['',70, 75, 80, 85, 90], fontsize=8, weight='bold')
ax3.tick_params(left=0, bottom=0)
ax1.text(dt.date(2000, 1, 4), 58, 'NDA-1(1999-2004)',size=9,color='#68aa55', weight='bold')
ax2.text(dt.date(2004, 6, 20), 87, 'UPA(2004-2014)',size=9,color='#e9887c', weight='bold')
ax3.text(dt.date(2014, 6, 4), 88, 'NDA-2(2014-2021)',size=9, color='#73d5bc', weight='bold')
ax1.text(-0.04, -0.08, '@DATAQUEST'+' '*127+'Source:European Central Bank', transform=ax.transAxes, color='#f0f0f0', backgroundcolor='#4d4d4d', size=9)
plt.show()
We have plotted the graph dividing it into three seperate categories. We have built two rows. In the first row we have plotted all together and in the second row we have plotted them seperately for more clarity. From the above graph we observe that the exchange rate for Indian rupee has kept on increasing from 1999 till 2021 from 40 rupees to 90 rupees respectively. The graph looks more like a linear curve.
In this section we will compare the exchange rates of three different countries.
We will follow the same method as we did earlier. First we will rename the column names to snakecase. Then we will count the values in the column and drop the non-numeric values. We will also convert the data-type to float. We will store these corrected columns in a new dataset. Lastly we will calculate the rolling mean for all the currency columns and make a line plot comparing the euro exchange rate data points for three countries.
exchange_rates.rename(columns = {'[Chinese yuan renminbi ]':'chinese_yuan', '[UK pound sterling ]':'UK_pound', '[Australian dollar ]':'Australian_dollar'}, inplace=True)
euro_to_chin_yuan = exchange_rates[['Time', 'chinese_yuan']]
euro_to_chin_yuan['chinese_yuan'].value_counts()
- 61 7.2862 5 7.3028 4 8.1288 4 7.7945 4 .. 7.6526 1 10.0857 1 10.3297 1 8.0933 1 8.3110 1 Name: chinese_yuan, Length: 4799, dtype: int64
euro_to_chin_yuan['chinese_yuan'] = euro_to_chin_yuan.loc[:,'chinese_yuan'].str.replace('-', '')
euro_to_chin_yuan = euro_to_chin_yuan.loc[euro_to_chin_yuan['chinese_yuan'] != '']
euro_to_chin_yuan['chinese_yuan'].astype(float)
euro_to_chin_yuan['chinese_yuan'].value_counts()
<ipython-input-18-cdcfa8e4612f>:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy euro_to_chin_yuan['chinese_yuan'] = euro_to_chin_yuan.loc[:,'chinese_yuan'].str.replace('-', '')
7.2862 5 8.1288 4 7.3823 4 7.7945 4 8.1586 4 .. 7.6526 1 10.0857 1 10.3297 1 8.0933 1 8.3110 1 Name: chinese_yuan, Length: 4798, dtype: int64
euro_to_chin_yuan['rolling_mean'] = euro_to_chin_yuan.loc[:, 'chinese_yuan'].rolling(30).mean()
euro_to_chin_yuan
Time | chinese_yuan | rolling_mean | |
---|---|---|---|
0 | 1999-01-04 | NaN | NaN |
1 | 1999-01-05 | NaN | NaN |
2 | 1999-01-06 | NaN | NaN |
3 | 1999-01-07 | NaN | NaN |
4 | 1999-01-08 | NaN | NaN |
... | ... | ... | ... |
5694 | 2021-01-04 | 7.9484 | 7.928793 |
5695 | 2021-01-05 | 7.9315 | 7.933457 |
5696 | 2021-01-06 | 7.9653 | 7.938373 |
5697 | 2021-01-07 | 7.9392 | 7.942507 |
5698 | 2021-01-08 | 7.9184 | 7.945823 |
5638 rows × 3 columns
euro_to_UK_pound = exchange_rates[['Time', 'UK_pound']]
euro_to_UK_pound['UK_pound'].value_counts()
- 62 0.87750 7 0.90430 7 0.84560 7 0.63040 7 .. 0.76660 1 0.87875 1 0.78090 1 0.71690 1 0.85218 1 Name: UK_pound, Length: 3470, dtype: int64
euro_to_UK_pound['UK_pound'] = euro_to_UK_pound.loc[:,'UK_pound'].str.replace('-', '')
euro_to_UK_pound = euro_to_UK_pound.loc[euro_to_UK_pound['UK_pound'] != '']
euro_to_UK_pound['UK_pound'].astype(float)
<ipython-input-21-37d42c923349>:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy euro_to_UK_pound['UK_pound'] = euro_to_UK_pound.loc[:,'UK_pound'].str.replace('-', '')
0 0.71110 1 0.71220 2 0.70760 3 0.70585 4 0.70940 ... 5694 0.90160 5695 0.90333 5696 0.90635 5697 0.90190 5698 0.90128 Name: UK_pound, Length: 5637, dtype: float64
euro_to_UK_pound['rolling_mean'] = euro_to_UK_pound.loc[:, 'UK_pound'].rolling(30).mean()
euro_to_UK_pound
Time | UK_pound | rolling_mean | |
---|---|---|---|
0 | 1999-01-04 | 0.71110 | NaN |
1 | 1999-01-05 | 0.71220 | NaN |
2 | 1999-01-06 | 0.70760 | NaN |
3 | 1999-01-07 | 0.70585 | NaN |
4 | 1999-01-08 | 0.70940 | NaN |
... | ... | ... | ... |
5694 | 2021-01-04 | 0.90160 | 0.902912 |
5695 | 2021-01-05 | 0.90333 | 0.903225 |
5696 | 2021-01-06 | 0.90635 | 0.903807 |
5697 | 2021-01-07 | 0.90190 | 0.904200 |
5698 | 2021-01-08 | 0.90128 | 0.904533 |
5637 rows × 3 columns
euro_to_Australian_dollar = exchange_rates[['Time', 'Australian_dollar']]
euro_to_Australian_dollar['Australian_dollar'].value_counts()
euro_to_Australian_dollar['Australian_dollar'] = euro_to_Australian_dollar.loc[:,'Australian_dollar'].str.replace('-', '')
euro_to_Australian_dollar = euro_to_Australian_dollar.loc[euro_to_Australian_dollar['Australian_dollar'] != '']
euro_to_Australian_dollar['Australian_dollar'].astype(float)
euro_to_Australian_dollar['rolling_mean'] = euro_to_Australian_dollar.loc[:, 'Australian_dollar'].rolling(30).mean()
euro_to_Australian_dollar
<ipython-input-23-d5b46f1b9eba>:3: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy euro_to_Australian_dollar['Australian_dollar'] = euro_to_Australian_dollar.loc[:,'Australian_dollar'].str.replace('-', '')
Time | Australian_dollar | rolling_mean | |
---|---|---|---|
0 | 1999-01-04 | 1.9100 | NaN |
1 | 1999-01-05 | 1.8944 | NaN |
2 | 1999-01-06 | 1.8820 | NaN |
3 | 1999-01-07 | 1.8474 | NaN |
4 | 1999-01-08 | 1.8406 | NaN |
... | ... | ... | ... |
5694 | 2021-01-04 | 1.5928 | 1.616687 |
5695 | 2021-01-05 | 1.5927 | 1.615687 |
5696 | 2021-01-06 | 1.5824 | 1.614323 |
5697 | 2021-01-07 | 1.5836 | 1.613193 |
5698 | 2021-01-08 | 1.5758 | 1.611753 |
5637 rows × 3 columns
Below we will plot the euro exhange rates for all the three countries and study their behavior.
#plot the line graph for above 3 countries using matplotlib style 'ggplot'
style.use('ggplot')
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1, figsize=(6, 8))
axes = [ax1, ax2, ax3]
for ax in axes:
ax1.plot(euro_to_chin_yuan['Time'], euro_to_chin_yuan['rolling_mean'], color='#ff3366')
# ax1.set_xticklabels([])
ax2.plot(euro_to_UK_pound['Time'], euro_to_UK_pound['rolling_mean'], color='#ff9966')
# ax2.set_xticklabels([])
ax3.plot(euro_to_Australian_dollar['Time'], euro_to_Australian_dollar['rolling_mean'], color='grey')
ax.tick_params(left=0, bottom=0)
for location in ['left', 'right', 'bottom', 'top']:
ax.spines[location].set_visible(False)
ax1.text(dt.date(1999,10,4), 10.8, 'China Yuan', color='#ff3366', weight='bold')
ax1.text(dt.date(2008,10,4), 10.8, 'Average exchange rate is ~ ¥8.61 per euro', color='#ff3366')
ax2.text(dt.date(1999,1,4), 0.84, 'Average exchange rate is\n ~ £0.77 per euro', color='#ff9966')
ax2.text(dt.date(1999,1,4), 0.9, 'UK Pound', color='#ff9966', weight='bold')
ax3.text(dt.date(1999,1,4), 1.95, 'Australian Dollar', color='grey', weight='bold')
ax3.text(dt.date(2010,5,4), 1.88, 'Average exchange rate is\n ~ $1.58 per euro', color='grey')
plt.show()
Above we plotted euro exchange rate for China, UK, and Australia in the first, second, and third rows respectively. We have also mentioned the average exchange rate for each country in the plot. Below we will explain the trend for these three countries one by one.
For China the exchange rate was at 8 yuan in 2008. Then it increased to 11 yuan in the year 2005 and till 2008 was almost at the same value. After that started to decrease gradually with small ups and downs and reached lowest (below 7) in the year 2016. Then it started increasing at a low pace and reached 8 yuan by 2020.
For UK in the year 2000 the exchange rate was lowest at 0.6 pounds. After that it started to increase with slight variation reaching ~ 0.9 pounds in the year 2009. After that till 2020, it is almost at the same value with occational ups and downs.
For Australia the euro exchange rate was at ~ 1.7 dollars from 2000 till 2008. Then there is a sharp rise in the dollar to 2 and a sudden decrease to 1.2 dollars by the year 2012. After 2012 it started to increase gradually and reached ~ 1.6 dollars by 2020.
The project we worked on is on Story Telling Data Visualization on Exchange Rates. Here we studied the yearly trend of euro exchange rate for different countries from 1999 till 2021. Before making any plot we cleaned the data by renaming the currency column of every country into snake-case from camal-case and Period\Unit column to Time column. We also calculated the rolling mean for the currency column in order to get a comparatively smooth curve. Below we list our observations:-
We studied the variation of euro exchange rates with US dollars in detail under the last three US presidents George W. Bush (2001-2009), Barack Obama (2009-2017), and Donald Trump (2017-2021). The average exchange rate is ~1.19 dollars per euro. During Bush's tenure the exchange rate which was at $1.013 in the year 2000, fell initially then rose gradually to $1.574 in the year 2008. Later it kept on fluctuating with slight decrease in the rate and reached $1.382 in the year 2014 during Obama's tenure. Then there is a sudden decrease. After the year 2016 there is a steady fluctuation and the value reached $1.216 by the end of Trumps tenure.
We studied the variation of euro exchange rate of Indian Rupeee. Here we studied the data under three different governments NDA-1 (1999-2004), UPA-1 (2004-2014) and NDA-2 (2014-2021). We observed that the Indian Rupee kept on increasing in a linear fashion from 40 rupees in 1999 to 90 rupees in 2021 with an average exchange rate of 64.52 rupees per euro.
At last we compared euro exchange rate for three different countries, China (Yuan), UK (Pound), and Australia (Dollar). Country's currency and euro rate change shows different patterns for each country.
The average exchange rate is 8.61 Yuan per euro. Yuan went through a peak between 2004 and 2008 at 11 Yuan per euro. Then dropped gradually below 7 Yuan per euro.
The average exchange rate for UK pound is 0.77 euro. The pound kept on increasing from 0.6 per euro in 2000 to 0.9 per euro in 2020.
The average exchange rate for Australian dollar is 1.58 per euro. The Australian dollar is almost steady except between 2008 and 2012, where it goes through a peak initially and then a dip.