<jupyter_start><jupyter_text>Title- Things- Stuff<jupyter_code>import pandas as pd
exchange_rates = pd.read_csv('euro-daily-hist_1999_2020.csv')

exchange_rates.head()
exchange_rates.tail()
exchange_rates.info()<jupyter_output><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  [Croatia[...]<jupyter_text>Data Cleaning<jupyter_code>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)
exchange_rates.reset_index(drop=True, inplace=True)
exchange_rates.head()
euro_to_dollar = exchange_rates[['Time', 'US_dollar']].copy()
euro_to_dollar['US_dollar'].value_counts() # 62 '-' characters
euro_to_dollar = euro_to_dollar[euro_to_dollar['US_dollar'] != '-']
euro_to_dollar['US_dollar'] = euro_to_dollar['US_dollar'].astype(float)
euro_to_dollar.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Int64Index: 5637 entries, 0 to 5698
Data columns (total 2 columns):
 #   Column     Non-Null Count  Dtype         
---  ------     --------------  -----         
 0   Time       5637 non-null   datetime64[ns]
 1   US_dollar  5637 non-null   float64       
dtypes: datetime64[ns](1), float64(1)
memory usage: 132.1 KB<jupyter_text>Rolling Mean<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline

plt.plot(euro_to_dollar['Time'], euro_to_dollar['US_dollar'])
plt.show()
plt.figure(figsize=(9,6))

plt.subplot(3,2,1)
plt.plot(euro_to_dollar['Time'], euro_to_dollar['US_dollar'])
plt.title('Original values', weight='bold')

for i, rolling_mean in zip([2, 3, 4, 5, 6],
                           [7, 30, 50, 100, 365]):
    plt.subplot(3,2,i)
    plt.plot(euro_to_dollar['Time'],
             euro_to_dollar['US_dollar'].rolling(rolling_mean).mean())
    plt.title('Rolling Window:' + str(rolling_mean), weight='bold')
    
plt.tight_layout() # Auto-adjusts the padding between subplots
plt.show()
euro_to_dollar['rolling_mean'] = euro_to_dollar['US_dollar'].rolling(30).mean()
euro_to_dollar<jupyter_output><empty_output><jupyter_text>Design Decisions Here are a few story ideas for our data:* We show how the euro-dollar rate has changed during the coronavirus pandemic. We can show the 2020 data and the 2016-2019 data as a baseline; we can use a line plot.* We show how the euro-dollar rate changed during the 2007-2008's financial crisis. We can also show the data for 2016 and 2009 for comparison; we can use a line plot.* We show comparatively how the euro-dollar rate changed under the last three US presidents (<NAME> (2001-2009), <NAME> (2009-2017), and <NAME> (2017-2021)); we can use a line plot.  Storytelling Data Visualization Examples  Financial Crisis Example<jupyter_code>#financial_crisis = euro_to_dollar.copy(
#                   )[(euro_to_dollar['Time'].dt.year >= 2006
#                   ) & (euro_to_dollar['Time'].dt.year <= 2009)]
#financial_crisis_7_8 = euro_to_dollar.copy(
#                   )[(euro_to_dollar.Time.dt.year >= 2007
#                   ) & (euro_to_dollar.Time.dt.year <= 2008)]
### Adding the FiveThirtyEight style
#import matplotlib.style as style
#style.use('fivethirtyeight')

### Adding the plot
#fig,ax = plt.subplots(figsize=(8,3))
#ax.plot(financial_crisis['Time'],
#        financial_crisis['rolling_mean'],
#        linewidth=1, color='#A6D785')

### Highlighting the 2007-2008 period
#ax.plot(financial_crisis_7_8['Time'],
#        financial_crisis_7_8['rolling_mean'],
#        linewidth=3, color='#e23d28')

### Highlihting the peak of the crisis
#ax.axvspan(xmin=13950, xmax=14140, ymin=0.09,
#           alpha=0.3, color='grey')

### Adding separate tick labels
#ax.set_xticklabels([])
#ax.set_yticklabels([])

#x = 13110
#for year in ['2006', '2007', '2008', '2009', '2010']:
#    ax.text(x, 1.13, year, alpha=0.5, fontsize=11)
#    x += 365

#y = 1.193   
#for rate in ['1.2', '1.3', '1.4', '1.5']:
#    ax.text(13020, y, rate, alpha=0.5, fontsize=11)
#    y += 0.1

### Adding a title and a subtitle    
#ax.text(13020, 1.67, "Euro-USD rate peaked at 1.59 during 2007-2008's financial crisis",
#        weight='bold')
#ax.text(13020, 1.63, 'Euro-USD exchange rates between 2006 and 2010',
#        size=12)

### Adding a signature
#ax.text(13020, 1.07, '©DATAQUEST' + ' '*94 + 'Source: European Central Bank',
#        color = '#f0f0f0', backgroundcolor = '#4d4d4d',
#        size=10)

### Add some transparency to the grid
#ax.grid(alpha=0.5)

#plt.show()<jupyter_output><empty_output><jupyter_text>The Three US Presidencies Example<jupyter_code>bush_obama_trump = euro_to_dollar.copy(
                   )[(euro_to_dollar['Time'].dt.year >= 2001) & (euro_to_dollar['Time'].dt.year < 2021)]
bush = bush_obama_trump.copy(
       )[bush_obama_trump['Time'].dt.year < 2009]
obama = bush_obama_trump.copy(
       )[(bush_obama_trump['Time'].dt.year >= 2009) & (bush_obama_trump['Time'].dt.year < 2017)]
trump = bush_obama_trump.copy(
       )[(bush_obama_trump['Time'].dt.year >= 2017) & (bush_obama_trump['Time'].dt.year < 2021)]<jupyter_output><empty_output><jupyter_text>Below, you'll notice we used matplotlib's functional approach to build the graphs. We use this approach because it offers more flexibility in arranging the subplots:* We first build three of the graphs on a 2-by-3 grid (this grid should have six subplots, but we only build three; the bottom row remains empty).* We then build only the bottom graph of a 2-by-1 grid (this grid should have two subplots; the top row remains empty).* The two grids are merged, and we end up with three graphs on the top row and one graph on the bottom row.<jupyter_code>### Adding the FiveThirtyEight style
style.use('fivethirtyeight')

### Adding the subplots
plt.figure(figsize=(12, 6))
ax1 = plt.subplot(2,3,1)
ax2 = plt.subplot(2,3,2)
ax3 = plt.subplot(2,3,3)
ax4 = plt.subplot(2,1,2)
axes = [ax1, ax2, ax3, ax4]

### Changes to all the subplots
for ax in axes:
    ax.set_ylim(0.8, 1.7)
    ax.set_yticks([1.0, 1.2, 1.4, 1.6])
    ax.set_yticklabels(['1.0', '1.2','1.4', '1.6'],
                   alpha=0.3)
    ax.grid(alpha=0.5)    
    

### Ax1: Bush
ax1.plot(bush['Time'], bush['rolling_mean'],
        color='#BF5FFF')
ax1.set_xticklabels(['', '2001', '', '2003', '', '2005', '',
                     '2007', '', '2009'],
                   alpha=0.3)
ax1.text(12300, 1.92, 'BUSH', fontsize=18, weight='bold',
        color='#BF5FFF')
ax1.text(12000, 1.8, '(2001-2009)', weight='bold',
        alpha=0.3)


### Ax2: Obama
ax2.plot(obama['Time'], obama['rolling_mean'],
        color='#ffa500')
ax2.set_xticklabels(['', '2009', '', '2011', '', '2013', '',
                     '2015', '', '2017'],
                   alpha=0.3)
ax2.text(15100, 1.92, 'OBAMA', fontsize=18, weight='bold',
        color='#ffa500')
ax2.text(14950, 1.8, '(2009-2017)', weight='bold',
         alpha=0.3)


### Ax3: Trump
ax3.plot(trump['Time'], trump['rolling_mean'],
        color='#00B2EE')
ax3.set_xticklabels(['2017', '', '2018', '', '2019', '',
                     '2020', '', '2021'],
                   alpha=0.3)
ax3.text(17650, 1.92, 'TRUMP', fontsize=18, weight='bold',
        color='#00B2EE')
ax3.text(17560, 1.8, '(2017-2021)', weight='bold',
         alpha=0.3)

### Ax4: Bush-Obama-Trump
ax4.plot(bush['Time'], bush['rolling_mean'],
        color='#BF5FFF')
ax4.plot(obama['Time'], obama['rolling_mean'],
        color='#ffa500')
ax4.plot(trump['Time'], trump['rolling_mean'],
        color='#00B2EE')
ax4.grid(alpha=0.5)
ax4.set_xticks([])

### Adding a title and a subtitle
ax1.text(10800, 2.35, 'EURO-USD rate averaged 1.22 under the last three US presidents',
         fontsize=20, weight='bold')
ax1.text(10800, 2.14, '''EURO-USD exchange rates under George W. Bush (2001 - 2009), Barack Obama (2009-2017),
and <NAME> (2017-2021)''',
        fontsize=16)

### Adding a signature
ax4.text(10700, 0.65, '©DATAQUEST' + ' '*103 + 'Source: European Central Bank',
        color = '#f0f0f0', backgroundcolor = '#4d4d4d',
        size=14)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1586671080216264, 'fraction_numerical': 0.07944389275074479, 'mean_word_length': 3.3223652837386743, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '320704', 'license': 'MIT', 'n_tokens_mistral': 3799, 'n_tokens_neox': 3193, 'n_words': 763, 'path': 'Storytelling - Data Visualization of Exchange Rates.ipynb', 'repo_name': 'karnak52/VIZ_Storytelling_Data_Visualization_Exchange_Rates', 'size': '9089'}