doncoding-ai / Data-Analysis

MIT License
1 stars 1 forks source link

Data analysis #1

Open doncoding-ai opened 1 year ago

doncoding-ai commented 1 year ago

This a data analysis and visualisation project using python

doncoding-ai commented 1 year ago

Guided Project: Storytelling Data Visualization on Exchange Rates

Introducing the Dataset

doncoding-ai commented 1 year ago
import pandas as pd

exchange_rates = pd.read_csv('euro-daily-hist_1999_2020.csv')
exchange_rates.head()
doncoding-ai commented 1 year ago
 xchange_rates.tail()
doncoding-ai commented 1 year ago

exchange_rates.info()

doncoding-ai commented 1 year ago

Data Cleaning

doncoding-ai commented 1 year ago
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()
doncoding-ai commented 1 year ago
/euro_to_dollar = exchange_rates[['Time', 'US_dollar']].copy()
euro_to_dollar['US_dollar'].value_counts() # 62 '-' characters
doncoding-ai commented 1 year ago
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()
doncoding-ai commented 1 year ago

Rolling Mean

doncoding-ai commented 1 year ago
import matplotlib.pyplot as plt
%matplotlib inline

plt.plot(euro_to_dollar['Time'], euro_to_dollar['US_dollar'])
plt.show()
doncoding-ai commented 1 year ago
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()
doncoding-ai commented 1 year ago
euro_to_dollar['rolling_mean'] = euro_to_dollar['US_dollar'].rolling(30).mean()
euro_to_dollar