This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import required libraries | |
| import pandas as pd | |
| import plotly.graph_objects as go | |
| import dash | |
| import dash_html_components as html | |
| import dash_core_components as dcc | |
| from dash.dependencies import Input, Output | |
| # Read the airline data into the pandas dataframe | |
| airline_data = pd.read_csv('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/airline_data.csv', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import required packages | |
| import pandas as pd | |
| import plotly.express as px | |
| import dash | |
| import dash_html_components as html | |
| import dash_core_components as dcc | |
| # Read the airline data into pandas dataframe | |
| airline_data = pd.read_csv('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/airline_data.csv', | |
| encoding = "ISO-8859-1", | |
| dtype={'Div1Airport': str, 'Div1TailNum': str, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df_can = pd.read_csv('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/Canada.csv') | |
| print('Data downloaded and read into a dataframe!') | |
| ! wget --quiet https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/world_countries.json | |
| print('GeoJSON file downloaded!') | |
| world_geo = r'https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/world_countries.json' # geojson file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np # useful for many scientific computing in Python | |
| import pandas as pd # | |
| #!pip3 install folium==0.5.0 | |
| import folium | |
| print('Folium installed and imported!') | |
| # define the world map | |
| world_map = folium.Map() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from wordcloud import WordCloud, STOPWORDS | |
| print ('Wordcloud imported!') | |
| import urllib | |
| # # open the file and read it into a variable alice_novel | |
| alice_novel = urllib.request.urlopen('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/alice_novel.txt').read().decode("utf-8") | |
| stopwords = set(STOPWORDS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_waffle_chart(categories, values, height, width, colormap, value_sign=''): | |
| # compute the proportion of each category with respect to the total | |
| total_values = sum(values) | |
| category_proportions = [(float(value) / total_values) for value in values] | |
| # compute the total number of tiles | |
| total_num_tiles = width * height # total number of tiles | |
| print ('Total number of tiles is', total_num_tiles) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # we can use the sum() method to get the total population per year | |
| df_tot = pd.DataFrame(df_can[years].sum(axis=0)) | |
| # change the years to type int (useful for regression later on) | |
| df_tot.index = map(int, df_tot.index) | |
| # reset the index to put in back in as a column in the df_tot dataframe | |
| df_tot.reset_index(inplace = True) | |
| # rename columns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df_can.sort_values(['Total'], ascending=False, axis=0, inplace=True) | |
| # get the top 5 entries | |
| df_top5 = df_can.head() | |
| # transpose the dataframe | |
| df_top5 = df_top5[years].transpose() | |
| df_top5.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np # useful for many scientific computing in Python | |
| import pandas as pd # primary data structure library | |
| %matplotlib inline | |
| import matplotlib as mpl | |
| import matplotlib.pyplot as plt | |
| ### type your answer here | |
| df_CI = df_can.loc[['India', 'China'], years] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //drop columns | |
| df.drop(['Unnamed: 0.1', 'Unnamed: 0'], axis=1, inplace=True) | |
| //count sample or get dimensions | |
| x_train_pr1.shape |