Answer To: Microsoft Word - 2018_ICT112_assignment_passenger_movements ICT112 TASK XXXXXXXXXX 2018 Semester 1,...
Abr Writing answered on Jun 01 2020
ICT112 Assignment.ipynb
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from flask import Flask, render_template, request, url_for, redirect, Markup\n",
"import os\n",
"import json\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"IMAGES_FOLDER = 'Images'\n",
"INDEX_PAGE = '/'\n",
"\n",
"def create_folder(folder): \n",
" if not os.path.exists(folder):\n",
" os.makedirs(folder)\n",
" \n",
"create_folder(IMAGES_FOLDER)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('./1.csv', encoding = 'utf8')\n",
"\n",
"df2 = pd.read_csv('./2.csv', encoding = 'utf8')\n",
"df2 = df2.drop(df2.index[[0,1,2,3,4,5,6,7,8]])\n",
"df2 = df2.iloc[[0,1,2,3,4,5,6,7,8,9,10,11]].reset_index().drop('index',axis=1)\n",
"df2 = df2[['Number of movements ; Total (Country of stay/residence) ; Short-term Visitors arriving ;']]\n",
"df2.columns = ['Tourists']\n",
"df2 = df2.apply(pd.to_numeric)\n",
"\n",
"#creating dataframe with information per year per airport\n",
"dfg_airport = df.groupby(['AIRPORT','Year'])\n",
"df_airports = dfg_airport.aggregate(np.sum).reset_index()\n",
"df_airports = df_airports.drop('Month',axis=1)\n",
"\n",
"#creating a list of uniquire airport names\n",
"airports = df['AIRPORT'].unique()\n",
"\n",
"#creating a dictionary of states with their respective airports\n",
"states_dict = {\n",
" \"New South Wales\": [\"BALLINA\",\"SYDNEY\",\"CANBERRA\",\"NEWCASTLE\"],\n",
" \"Northern Territory\": [\"ALICE SPRINGS\",\"DARWIN\"],\n",
" \"Queensland\":[\"BRISBANE\",\"CAIRNS\",\"GOLD COAST\",\"HAMILTON ISLAND\",\"MACKAY\",\"ROCKHAMPTON\",\"SUNSHINE COAST\",\"TOWNSVILLE\"],\n",
" \"South Australia\":[\"ADELAIDE\"],\n",
" \"Tasmania\":[\"HOBART\",\"LAUNCESTON\"],\n",
" \"Vicoria\":[\"MELBOURNE\"],\n",
" \"Western Australia\":[\"KARRATHA\",\"PERTH\"],\n",
"}\n",
"\n",
"#creating a dictionary of states with their respective information dataframes\n",
"df_states_dict = {}\n",
"for state in states_dict:\n",
" df_states_dict[state] = df_airports[df_airports['AIRPORT'].isin(states_dict[state])].drop('AIRPORT',axis=1)\n",
" df_states_dict[state] = df_states_dict[state].groupby(['Year']).aggregate(np.sum).reset_index()\n",
" \n",
"#creating seasonal dataframes per airport \n",
"df_summer = df[df['Month'].isin([12,1,2])].drop('Month',axis=1).groupby(['AIRPORT','Year']).aggregate(np.sum).reset_index()\n",
"df_winter = df[df['Month'].isin([6,7,8])].drop('Month',axis=1).groupby(['AIRPORT','Year']).aggregate(np.sum).reset_index()\n",
"\n",
"#creating dictionaries of states with their respective seasonal information dataframes\n",
"df_states_summer_dict = {}\n",
"for state in states_dict:\n",
" df_states_summer_dict[state] = df_summer[df_summer['AIRPORT'].isin(states_dict[state])].drop('AIRPORT',axis=1)\n",
" df_states_summer_dict[state] = df_states_summer_dict[state].groupby(['Year']).aggregate(np.sum).reset_index() \n",
"df_states_winter_dict = {}\n",
"for state in states_dict:\n",
" df_states_winter_dict[state] = df_winter[df_winter['AIRPORT'].isin(states_dict[state])].drop('AIRPORT',axis=1)\n",
" df_states_winter_dict[state] =...