I have uploaded the files

1 answer below »
Answered Same DayMay 29, 2020ICT112University of the Sunshine Coast

Answer To: I have uploaded the files

Abr Writing answered on Jun 01 2020
139 Votes
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing required packages"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_ty
pe": "markdown",
"metadata": {},
"source": [
"## Setting various constants and creating required folders"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"HTML_FOLDER = 'HTML'\n",
"IMAGES_FOLDER = 'Images'\n",
"INDEX_PAGE = 'index.htm'\n",
"TOTAL_PAX_PER_YEAR_PAGE = 'total-passengers-per-year.html'\n",
"TOTAL_PAX_PER_YEAR_PER_AIRPORT_PAGE = 'total-passengers-per-year-per-airport.html'\n",
"TOTAL_PAX_PER_YEAR_PER_STATE_PAGE = 'total-passengers-per-year-per-state.html'\n",
"RATE_OF_TOTAL_PAX_PER_YEAR_PER_STATE_PAGE = 'rate-of-total-passengers-per-year-per-state.html'\n",
"SEASONAL_PAX_PER_AIRPORT_PAGE = 'seasonal-passengers-per-year-per-airport.html'\n",
"SEASONAL_PAX_PER_STATE_PAGE ='seasonal-passengers-per-year-per-state.html'\n",
"TOURISTS_VS_RESIDENTS_PAGE = 'tourists-vs-residents-page.html'\n",
"\n",
"def create_folder(folder): \n",
" if not os.path.exists(folder):\n",
" os.makedirs(folder)\n",
" \n",
"create_folder(IMAGES_FOLDER)\n",
"create_folder(HTML_FOLDER)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a Data Frames from given csv files\n",
"Renaming the column names to improve readability. Also remove extra information we dont need."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": false
},
"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)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Processing dataframes based on our requirements\n",
"Sifting though data to create information blocks based on our requirements"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#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 =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here