<jupyter_start><jupyter_text>Data Visualization Tutorial 1  Import Required Libraries<jupyter_code># import required library functions
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd<jupyter_output><empty_output><jupyter_text>Load UN Canadian Immigration Data The data is of yearly country wise immigration into Canada from around the globe between 1980 and 2013<jupyter_code># load data, skip the top 20 and bottom 2 rows as they do not contain relevant data
df_canada = pd.read_excel('data/canada.xlsx',
                          sheet_name = 'Canada by Citizenship',
                          skiprows = range(20),
                          skipfooter = 2)<jupyter_output><empty_output><jupyter_text>Explore Dimentions of the Data<jupyter_code># top 5 rows
df_canada.head()
# bottom 5 rows
df_canada.tail()
# schema information
df_canada.info()
# size of data frame
df_canada.shape<jupyter_output><empty_output><jupyter_text>Clean and Prepare the Data<jupyter_code># conversion index and columns to lists
df_canada.columns.tolist()
df_canada.index.tolist()

# remove unnecessary columns
# in pandas axis=0 re|presents rows (default) and axis=1 represents columns.
df_canada.drop(['AREA','REG','DEV','Type','Coverage'], axis=1, inplace=True)

# rename some columns to make better sense
df_canada.rename(columns={'OdName':'Country', 'AreaName':'Continent', 'RegName':'Region'}, inplace=True)
# convert all column names to strings
df_canada.columns = list(map(str, df_canada.columns))

# full range of the time series
years = list(map(str, range(1980, 2014)))

# add Total column
df_canada['Total'] = df_canada.sum(axis=1)
# size of data frame
df_canada.shape<jupyter_output><empty_output><jupyter_text>Validate Data<jupyter_code># check for missing data
df_canada.isnull().sum()

# data numerical summary
df_canada.describe()<jupyter_output><empty_output><jupyter_text>Index the Data Enables lookup by country<jupyter_code># index data by country
df_canada.set_index('Country', inplace=True)
# print sample data
print(df_canada.loc['Japan'])
#print(df_canada.loc['Japan', 2000])<jupyter_output><empty_output><jupyter_text>Visualize Continuous Time Series  Visualize immigration from Haiti to Canada from 1980 to 2013.<jupyter_code># plot immigration pattern for Haiti
df_canada.loc['Haiti', years].transpose().plot(kind = 'line')
plt.title('Immigration from Haiti')
plt.ylabel('Number of immigrants')
plt.xlabel('Years')

plt.show()<jupyter_output><empty_output><jupyter_text>Visualize immigration from India and China to Canada from 1980 to 2013.<jupyter_code># plot immigration pattern for India and China
df_IndiaChina = df_canada.loc[['India', 'China'], years]
df_IndiaChina.transpose().plot(kind = 'line')
plt.title('Immigration from India and China')
plt.ylabel('Number of immigrants')
plt.xlabel('Years')

plt.show()<jupyter_output><empty_output><jupyter_text>Visualize Discrete Data  Visualize top 5 immigration contributions into Canada<jupyter_code># sort data by Total
df_canada.sort_values(by='Total', ascending=False, axis=0, inplace=True)

# pick top 5 contibutors
df_top5 = df_canada.head(5)['Total']

# print data.
df_top5.head()
# plot immigration pattern of top 5
df_top5.transpose().plot(kind = 'bar')
plt.title('Top 5 Immigration Contributors')
plt.ylabel('Number of immigrants')
plt.xlabel('Countries')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10954891622729936, 'fraction_numerical': 0.01698886936145284, 'mean_word_length': 6.312633832976445, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '322743', 'license': 'Apache-2.0', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1096, 'n_words': 298, 'path': 'DataVisualization/DataVisualization_1.ipynb', 'repo_name': 'sumandeepb/A10_DataPreperationAndVisualization', 'size': '3414'}