<jupyter_start><jupyter_text>Analysis of Gross national income (GNI) Imports and set magics:<jupyter_code># Importing API from DST, specifying the language
import pydst                          
Dst = pydst.Dst(lang='en')            
# Importing packages for data analysis 
import pandas as pd                   
import numpy as np                    
import matplotlib.pyplot as plt       
import ipywidgets as widgets             

# Autoreloading modules when code is run
%load_ext autoreload
%autoreload 2

# Local modules
import dataproject<jupyter_output>The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload<jupyter_text>Read and clean data **Read the  data** from DSTI. We want to analyze the table named NKN2 including the Danish gross national income  by transaction and price unit:<jupyter_code>#In order to retrieve the dataset 'NKN2' from DST, we run the following code to extract the desided variables and shows the first and last three rows of the dataset
fuldt_dataset = Dst.get_data(table_id = 'NKN2',
                             variables = {'TRANSAKT':['B5GQD'], 
                                          'PRISENHED':['V'], 
                                          'SÆSON':['Y'],
                                          'TID':['*']})       

pd.concat([fuldt_dataset.head(3), fuldt_dataset.tail(3)])     
#We now remove redundant variables, so only time and GNI remain.
df1 = fuldt_dataset.drop(columns=['TRANSAKT', 'PRISENHED', 'SÆSON'], axis=1) 
df1.columns = ['Tid', 'GNI']                        
df1['GNI'].replace('..',np.nan, inplace=True)
df1.dropna(inplace=True)       
pd.concat([df1.head(3), df1.tail(3)])<jupyter_output><empty_output><jupyter_text>Time and GNI is extracted as arrays. Empty cells are removed, converting the variable to a float type:<jupyter_code>#Checking for empty cells, removing if empty cells                
df1['GNI'].replace('..',np.nan, inplace=True)
df1.dropna(inplace=True) 
pd.concat([df1.head(3), df1.tail(3)])     
#Barplot of GNI over time
plt.figure(figsize=(14,7))
plt.xlabel('\nYear and quarter', size=18)           # Sets label on t variable
plt.ylabel('GNI size', size=18)                     # Sets label on GNI variable
plt.bar(df1['Tid'], df1['GNI'], label='GNI')                          # Plots GNI
plt.title('GNI values for the entire dataset\n', size=25)  # Sets title of the plot
plt.xticks(df1['Tid'][4:] , rotation='vertical')                # Makes time units appear on the x axis
plt.locator_params(axis='x', nbins=len(df1['Tid'][4:])/2) 
plt.show()<jupyter_output><empty_output><jupyter_text>Analyzing the dataset **Now, we are interested at looking at the growth rate and descriptive statistics of the dataset.** Summarizing the data, we find:<jupyter_code>df1['GNI'].describe()<jupyter_output><empty_output><jupyter_text>In the period from 1991 to 2019 Q3, we see that the mean for these observations are about 385 bill. DKK, while the minimum and maximum are, 210 bill. DKK and 588 bill. DKK., respectively.  In order to be able to **explore the raw data**, we now plot the growth rate of GNI<jupyter_code>#Calculating the growth rate
df1['Growth'] = df1['GNI'].pct_change()<jupyter_output><empty_output><jupyter_text>Visualization<jupyter_code>plt.figure(figsize=(14,7))
plt.xlabel('\nYear and quarter', size=18)          
plt.ylabel('GNI growth', size=18)                  
plt.bar(df1['Tid'], df1['Growth'], label='Growth of GNI')               
plt.title('GNI Growth Rate\n', size=25)  
plt.xticks(df1['Tid'][4:], rotation='vertical')       
plt.locator_params(axis='x', nbins=len(df1['Tid'][4:])/2)<jupyter_output><empty_output><jupyter_text>In the period from 1991 to 2019 Q3, we see that the mean for these observations are about 385 bill. DKK, while the minimum and maximum are, 210 bill. DKK and 588 bill. DKK., respectively.   Calculating moving averages We now want to calculate the exponential moving averages of GNI in order to better capture the movement of the trend:<jupyter_code>#df1['EMA']=df1['Growth'].ewm(span=20).mean().plot(style='k')
df1['EMA']=df1['Growth'].ewm(span=20).mean()


#Plotting Exponential Moving Averages
plt.figure(figsize=(14,7))
plt.xlabel('\nYear and quarter', size=18)          
plt.ylabel('Growth', size=18)                  
plt.bar(df1['Tid'], df1['EMA'], label='Growth of GNI')               
plt.title('Exponential Moving Averages\n', size=25)  
plt.xticks(df1['Tid'][4:], rotation='vertical')       
plt.locator_params(axis='x', nbins=len(df1['Tid'][4:])/2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12587719298245614, 'fraction_numerical': 0.025657894736842105, 'mean_word_length': 3.4541015625, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '426223', 'license': 'MIT', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1451, 'n_words': 422, 'path': 'dataproject/dataproject.ipynb', 'repo_name': 'zenghijacob/projects-2020-zjr-hrv', 'size': '4560'}