Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Already give to the agent

1 answer below »
Answered Same Day Jun 02, 2020

Solution

Abr Writing answered on Jun 03 2020
143 Votes
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing necessary dependencies"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from flask import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining Constants"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"HOME_PAGE = 'index.html'\n",
"PAGE_1 = 'total-passengers-per-year.html'\n",
"PAGE_2 = 'total-passengers-per-year-per-airport.html'\n",
"PAGE_3 = 'total-passengers-per-year-per-state.html'\n",
"PAGE_4 = 'seasonal-passengers-per-year-per-airport.html'\n",
"PAGE_5 ='seasonal-passengers-per-year-per-state.html'\n",
"PAGE_6 = 'tourists-vs-residents-page.html'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining Servers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from flask import Flask\n",
"app = Flask(__name__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reading and Manipulating Data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df1 = 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
esidence) ; Short-term Visitors a
iving ;']]\n",
"df2.columns = ['Tourists']\n",
"df2 = df2.apply(pd.to_numeric)\n",
"\n",
"\n",
"dfg_airport = df1.groupby(['AIRPORT','Year'])\n",
"df_airports = dfg_airport.aggregate(np.sum).reset_index()\n",
"df_airports = df_airports.drop('Month',axis=1)\n",
"\n",
"airports = df1['AIRPORT'].unique()\n",
"\n",
"states_dict = {\n",
" \"New South Wales\": [\"BALLINA\",\"SYDNEY\",\"CANBERRA\",\"NEWCASTLE\"],\n",
" \"Northern Te
itory\": [\"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",
"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",
"df_summer = df1[df1['Month'].isin([12,1,2])].drop('Month',axis=1).groupby(['AIRPORT','Year']).aggregate(np.sum).reset_index()\n",
"df_winter = df1[df1['Month'].isin([6,7,8])].drop('Month',axis=1).groupby(['AIRPORT','Year']).aggregate(np.sum).reset_index()\n",
"\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",
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here