# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="HA_PFuoRgisM"
# !pip install sorted-months-weekdays --quiet
# !pip install sort-dataframeby-monthorweek --quiet

# + id="5ECDwY3lfQXs"
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import calendar
from sorted_months_weekdays import *
from sort_dataframeby_monthorweek import *


# + colab={"base_uri": "https://localhost:8080/", "height": 444} id="ScY_EJwZfacU" outputId="1f7113ab-4f97-4176-84d3-cf95a74d16f2"
data = pd.read_csv("/content/covid_impact_on_airport_traffic.csv")
data.head()

# + colab={"base_uri": "https://localhost:8080/"} id="IEBgnqXKfafO" outputId="be379daa-fc78-4b53-9f7d-935dd28d62fd"
data.shape

# + colab={"base_uri": "https://localhost:8080/"} id="byrqBYbeltcj" outputId="e0644d70-0483-4a11-ca23-0af68c1d24ff"
data.duplicated().sum()

# + colab={"base_uri": "https://localhost:8080/"} id="IvyQsJYVgPMi" outputId="2d5ab05a-3b47-4e0c-88e4-4a2123207a1b"
data.isnull().sum()

# + id="uUHesE8iNz9E"
data['long'] = data['Centroid'].apply(lambda x: x[6:-1].split(' ')[0])
data['lat'] = data['Centroid'].apply(lambda x: x[6:-1].split(' ')[1])

# + colab={"base_uri": "https://localhost:8080/", "height": 245} id="BzDntZjvQDuB" outputId="10d524be-5dcf-4db0-fdf1-7a4e201b57f4"
data.head(2)

# + [markdown] id="aup6W9aYhGGy"
# ## **Exploratory Data Analysis**
#
#

# + colab={"base_uri": "https://localhost:8080/"} id="gBFoDd9HhErc" outputId="b40dc8d4-07d6-4e52-ffab-a8b5ef41a49c"
data[['Country']].value_counts().sort_values()

# + colab={"base_uri": "https://localhost:8080/", "height": 575} id="o-hH9QP8reji" outputId="37fd3ae5-b60f-4a9a-802f-198302f89a85"
data[['Country']].value_counts().plot(kind='bar', figsize=(8,6), title="Number Of Countries")

# + id="1bkSK3ftwTyk" colab={"base_uri": "https://localhost:8080/", "height": 514} outputId="bbab1919-3662-4f0e-aa44-cd5d668ca5b0"
data[['State']].value_counts().plot(kind='bar', figsize=(10,6), title='Count of States')

# + id="xFghBTwMwuLF" colab={"base_uri": "https://localhost:8080/", "height": 525} outputId="e4058a45-8323-4a8f-cc2e-ab16ce06b53c"
data[['City']].value_counts().plot(kind='bar', figsize=(10,6), title='Count of Cities')

# + id="tDLuqPUohElQ" colab={"base_uri": "https://localhost:8080/"} outputId="e8e791c4-4590-44b9-f141-581218dc71fc"
data[['AirportName']].value_counts()

# + id="ALrmjzTJwTvi" colab={"base_uri": "https://localhost:8080/", "height": 624} outputId="cb3c2a09-0df6-49cf-da5a-8153934cd578"
data[['AirportName']].value_counts().plot(kind='bar', figsize=(10,6), title='Count of Airports')

# + id="lQzWGyy03ZMD"
data = data.sort_values('Date')
data['New_Date'] = pd.to_datetime(data['Date']).dt.strftime('%d-%m-%Y')
data['Year'] = pd.DatetimeIndex(data['Date']).year
data['Month'] = pd.to_datetime(data['Date']).dt.month_name()
data['Day'] = pd.to_datetime(data['Date']).dt.day_name()

# + id="PNKTEvgR6StX" colab={"base_uri": "https://localhost:8080/", "height": 228} outputId="b38a2a45-e219-4096-fb72-f1e7ae441518"
data.head(2)

# + id="Uf6BODp4hEN7" colab={"base_uri": "https://localhost:8080/", "height": 408} outputId="f6ca2493-5af0-40fb-e666-3f4a364c720b"
data[['Month']].value_counts().plot(kind='barh', figsize=(10,6), title='Month Counts')

# + id="Plo1TjpUhELL" colab={"base_uri": "https://localhost:8080/", "height": 445} outputId="54fd9f07-d958-4ffb-fdb3-85a13f527f79"
df_weekday = pd.DataFrame(data["Day"].value_counts())
p = df_weekday.plot.pie(y='Day', figsize=(7, 7))
p.set_title("Day of The Week Records")

# + id="qa279sZrhEJH" colab={"base_uri": "https://localhost:8080/", "height": 354} outputId="d3779e50-b5c0-4953-efb4-b13cb066ebf8"
sns.distplot(data['PercentOfBaseline'])

# + id="rqM3TRIP4Cuq" colab={"base_uri": "https://localhost:8080/", "height": 387} outputId="bd0d8125-51a7-4525-bafa-b4f38e022a38"
sns.displot(data, x="PercentOfBaseline", hue='Country', palette='husl', kind="kde")

# + [markdown] id="lzluw-dFGTwA"
# ### Average Percent of Baseline for Each Country (Month & Weekdays)

# + id="MrjXvuI9abBh" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="cc664078-cd57-437b-a844-8ddcca979947"
for i in data['Country'].unique():
  df_mnth = data[['PercentOfBaseline', 'Month']][data['Country']==i].sort_values('Month')
  df_mnth_avg = df_mnth.groupby('Month', as_index=False)['PercentOfBaseline'].mean()
  df_sort_month = Sort_Dataframeby_Month(df=df_mnth_avg,monthcolumnname='Month')
  df_sort_month.plot.bar(x='Month', y='PercentOfBaseline',figsize=(12,7))
  plt.ylabel("Average percent of Baseline",size=15)
  plt.xlabel("Month",size=15)
  plt.title(i, size=20)
  plt.show()

# + id="2oF9BPhKiZCz" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="3eeff47c-bf0a-41d5-f978-230c47e19268"
for i in data['Country'].unique():
  df = data[['PercentOfBaseline', 'Day']][data['Country']==i]
  df_day = df.groupby('Day', as_index=False)['PercentOfBaseline'].mean()
  sort_days = Sort_Dataframeby_Weekday(df=df_day,Weekdaycolumnname='Day')
  sort_days.plot.bar(x='Day', y='PercentOfBaseline',figsize=(10,6))
  plt.ylabel("Average percent of Baseline",size=12)
  plt.xlabel("Day",size=12)
  plt.title(i, size=20)
  plt.show()


# + [markdown] id="NQTSKnVdvHl4"
# ### Analysis For Chile 

# + id="2-eZCC3OhEHH"
chile = data[data['Country']== 'Chile']

# + id="3yPyTDGShEEz" colab={"base_uri": "https://localhost:8080/", "height": 211} outputId="675211e6-f12b-48af-e0a3-c4b54fc3ccd6"
chile = chile.set_index('New_Date')
chile.head(1)

# + id="_A-aUDEIhEC1" colab={"base_uri": "https://localhost:8080/", "height": 458} outputId="b3ecb28f-aeb4-474b-fa6f-b444787fcefd"
for i in chile['AirportName'].unique():
  df = chile[chile['AirportName']== i]

  fig = plt.figure(figsize=(12,7))
  sns.lineplot(data=df, x ="Date", y="PercentOfBaseline")
  plt.ylabel("PercentOfBaseline")
  plt.xlabel("Date")

  plt.title(i)
  plt.grid()
plt.show()

# + [markdown] id="H_i2zuu0Y-PO"
# Stay tuned for more analysis and notes on this..

StarcoderdataJupyterScriptsDedupFiltered