{"id":654,"date":"2020-09-28T00:32:48","date_gmt":"2020-09-28T07:32:48","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=654"},"modified":"2020-09-28T00:32:49","modified_gmt":"2020-09-28T07:32:49","slug":"107-tsa-data-2020-vs-2019","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2020\/09\/107-tsa-data-2020-vs-2019\/","title":{"rendered":"#107: TSA Data 2020 vs 2019"},"content":{"rendered":"<p>#107: TSA Data 2020 vs 2019<\/p>\n<p>The TSA has started to publish the daily volume of passengers going through checkpoints on its website. The data set also includes the numbers from 2019 in order to measure the impact of travel as a result of COVID-19.<\/p>\n<p>https:\/\/www.tsa.gov\/coronavirus\/passenger-throughput<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/09\/ex107.png?resize=1080%2C756\" alt=\"\" width=\"1080\" height=\"756\" class=\"alignnone size-full wp-image-655\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/09\/ex107.png?w=2000&amp;ssl=1 2000w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/09\/ex107.png?resize=300%2C210&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/09\/ex107.png?resize=1024%2C717&amp;ssl=1 1024w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/09\/ex107.png?resize=768%2C538&amp;ssl=1 768w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/09\/ex107.png?resize=1536%2C1075&amp;ssl=1 1536w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/09\/ex107.png?resize=1200%2C840&amp;ssl=1 1200w\" sizes=\"(max-width: 1080px) 100vw, 1080px\" \/><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom bs4 import BeautifulSoup\r\nimport requests\r\nimport numpy as np\r\nimport pandas as pd\r\nfrom matplotlib import pyplot as plt\r\nimport seaborn as sns\r\nsource = requests.get('https:\/\/www.tsa.gov\/coronavirus\/passenger-throughput').text\r\nsoup = BeautifulSoup(source, 'lxml')\r\n\r\nrow = soup.find_all(&quot;tr&quot;)\r\n\r\ndata = &#x5B;]\r\nfor i in row&#x5B;1:]:\r\n    string = i.get_text()\r\n    a = string.split(&quot;\\n&quot;)\r\n    data.append(a)\r\n\r\nprint(data)\r\n\r\ndf = pd.DataFrame(data, columns=&#x5B;'Date','This Year','Last Year','Empty'])\r\nprint(df.dtypes)\r\n\r\ndf&#x5B;'This Year'] = df&#x5B;'This Year'].replace(',','', regex=True)\r\ndf&#x5B;'Last Year'] = df&#x5B;'Last Year'].replace(',','', regex=True)\r\ndf&#x5B;'This Year'] = pd.to_numeric(df&#x5B;'This Year'])\r\ndf&#x5B;'Last Year'] = pd.to_numeric(df&#x5B;'Last Year'])\r\ndf&#x5B;'Date']= pd.to_datetime(df&#x5B;'Date'])\r\ndf&#x5B;'Percent Change'] = df&#x5B;'This Year'] \/ df&#x5B;'Last Year'] -1\r\n\r\nplt.clf()\r\n\r\nsns.set_style(&quot;whitegrid&quot;)\r\nsns.set_context(&quot;poster&quot;, font_scale = 1, rc={&quot;grid.linewidth&quot;: 0.6})\r\nf, ax = plt.subplots(figsize=(20,14))\r\n# top chart\r\nplt.subplot(2, 1, 1)\r\nax = plt.subplot(2, 1, 1)\r\nplt.subplots_adjust(top=0.95, hspace=0.3) # adds padding in between both charts\r\nsns.lineplot(data = df, x = 'Date', y= 'This Year')\r\nsns.lineplot(data = df, x = 'Date', y= 'Last Year')\r\n\r\nplt.ylabel('Number of Passengers')\r\nplt.xlabel('Date')\r\nplt.title('Passenger Throughput')\r\nplt.legend(&#x5B;'This Year','Last Year'])\r\nax.set_yticklabels(&#x5B;'{:,}'.format(int(x)) for x in ax.get_yticks().tolist()])\r\n\r\n#bottom chart\r\nplt.subplot(2, 1, 2)\r\nax2 = plt.subplot(2, 1, 2)\r\n\r\nsns.lineplot(data = df, x = 'Date', y= 'Percent Change')\r\nplt.ylabel('')\r\nplt.xlabel('Date')\r\nplt.title('% Change 2020 vs 2019')\r\nplt.legend(&#x5B;'% Change in Passengers'])\r\nax2.set_yticks(sorted(&#x5B; round(i,1) for i in np.arange(-1.0,0.1,.1)],reverse=True))\r\n\r\n\r\nax2.set_yticklabels(&#x5B;'0%','-10%','-20%', '-30%', '-40%','-50%','-60%','-70%', '-80%', '-90%', &quot;-100%&quot;])\r\nsns.set_context(&quot;poster&quot;, font_scale = 1, rc={&quot;grid.linewidth&quot;: 0.6})\r\n\r\nymin = df&#x5B;'Percent Change'].min()\r\nfilt = df&#x5B;'Percent Change'] == df&#x5B;'Percent Change'].min()\r\nxmin = df.loc&#x5B;filt]&#x5B;'Date'].min()\r\n\r\nyrecent = df.iloc&#x5B;0,4]\r\nxrecent = df.iloc&#x5B;0,0]\r\n\r\n#show the min value\r\nax2.annotate('Lowest Point ' + str(&quot;{:.1f}&quot;.format(ymin*100))+&quot;%&quot;, xy=(xmin, ymin), xytext=(xmin, ymin+.2),\r\n            arrowprops=dict(facecolor='black', shrink=0.05),\r\n            horizontalalignment='center', verticalalignment='top'\r\n            #arrowprops=dict(facecolor='black', shrink=0.05),\r\n            )\r\n\r\n#show the most recent value\r\nax2.annotate('Yesterday ' + str(&quot;{:.1f}&quot;.format(yrecent*100))+&quot;%&quot;, xy=(xrecent, yrecent), xytext=(xrecent, yrecent+.2),\r\n            arrowprops=dict(facecolor='black', shrink=0.05),\r\n            horizontalalignment='right', verticalalignment='top'\r\n            #arrowprops=dict(facecolor='black', shrink=0.05),\r\n            )\r\n\r\nplt.savefig('ex107.png')\r\nplt.show()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#107: TSA Data 2020 vs 2019 The TSA has started to publish the daily volume of passengers going through checkpoints on its website. The data set also includes the numbers from 2019 in order to measure the impact of travel as a result of COVID-19. https:\/\/www.tsa.gov\/coronavirus\/passenger-throughput from bs4 import BeautifulSoup import requests import numpy as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-654","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-ay","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1912,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/372-tsa-data-number-of-passengers-at-usa-airport-checkpoints\/","url_meta":{"origin":654,"position":0},"title":"#372 TSA data: Number of passengers at USA airport checkpoints","author":"gantovnik","date":"2023-08-09","format":false,"excerpt":"Good news for the aerospace industry because the number of passengers passing through TSA checkpoints this year is the same as in 2019 (before COVID-19). [code language=\"python\"] import pandas as pd import numpy as np import math import matplotlib.pyplot as plt from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap,geom_smooth,labs, scale_x_continuous,geom_line\u2026","rel":"","context":"In &quot;aerospace&quot;","block_context":{"text":"aerospace","link":"https:\/\/gantovnik.com\/bio-tips\/category\/aerospace\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/tsa_2023_08.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/tsa_2023_08.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/tsa_2023_08.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/tsa_2023_08.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/tsa_2023_08.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/tsa_2023_08.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1032,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/184-creating-a-boxplot-using-seaborn\/","url_meta":{"origin":654,"position":1},"title":"#183 Creating a boxplot using seaborn","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"[code language=\"python\"] import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import os os.chdir(r'D:\\projects\\wordpress\\ex184') os.getcwd() url = \"https:\/\/archive.ics.uci.edu\/ml\/machine-learning-databases\/auto-mpg\/auto-mpg.data\" df = pd.read_csv(url) column_names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'year', 'origin', 'name'] df = pd.read_csv(url, names= column_names, delim_whitespace=True) print(df.head()) #Convert the horsepower and\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":2158,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/421-plot-a-pandas-data-frame-for-loops-on-columns\/","url_meta":{"origin":654,"position":2},"title":"#421 Plot a pandas data frame for loops on columns","author":"gantovnik","date":"2024-05-04","format":false,"excerpt":"[code language=\"python\"] import numpy as np import pandas as pd import matplotlib.pyplot as plt np.random.seed(2023) df = pd.DataFrame({ \"x\": np.linspace(0, 1, 10), \"A\": np.random.rand(10), \"B\": np.random.rand(10), \"C\": np.random.rand(10), }) for column in df: if column != 'x': plt.plot(df['x'], df[column],label=f\"x vs. {column}\") plt.scatter(df['x'], df[column]) plt.title(\"Performance\") plt.grid() plt.xlabel('x') plt.ylabel('Efficiency') plt.legend() plt.show() plt.savefig('ex421.png',\u2026","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex421.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex421.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex421.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1028,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/183-creating-a-histogram-using-seaborn\/","url_meta":{"origin":654,"position":3},"title":"#184 Creating a histogram using seaborn","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"[code language=\"python\"] import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import os os.chdir(r'D:\\projects\\wordpress\\ex183') os.getcwd() url = \"https:\/\/archive.ics.uci.edu\/ml\/machine-learning-databases\/auto-mpg\/auto-mpg.data\" df = pd.read_csv(url) column_names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'year', 'origin', 'name'] df = pd.read_csv(url, names= column_names, delim_whitespace=True) print(df.head()) #Convert the horsepower and\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1041,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/186-generate-the-feature-importance\/","url_meta":{"origin":654,"position":4},"title":"#186 Generate the feature importance","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"[code language=\"python\"] import pandas as pd import seaborn as sns import os import matplotlib.pyplot as plt os.chdir(r'D:\\projects\\wordpress\\ex186') sns.set(style=\"ticks\") # read the downloaded input data (marketing data) df = pd.read_csv('https:\/\/raw.githubusercontent.com\/TrainingByPackt\/Big-Data-Analysis-with-Python\/master\/Lesson07\/Dataset\/bank.csv', sep=';') df['y'].replace(['yes','no'],[1,0],inplace=True) df['default'].replace(['yes','no'],[1,0],inplace=True) df['housing'].replace(['yes','no'],[1,0],inplace=True) df['loan'].replace(['yes','no'],[1,0],inplace=True) corr_df = df.corr() sns.heatmap(corr_df, xticklabels=corr_df.columns.values, yticklabels=corr_df.columns.values, annot = True, annot_kws={'size':12}) heat_map=plt.gcf(); heat_map.set_size_inches(10,5) plt.xticks(fontsize=10); plt.yticks(fontsize=10); plt.savefig('ex186a.jpg', dpi=300)\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1037,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/185-creating-a-scatter-plot-using-seaborn\/","url_meta":{"origin":654,"position":5},"title":"#185 Creating a scatter plot using seaborn","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"[code language=\"python\"] import matplotlib.pyplot as plt import numpy as np import pandas as pd import os import seaborn as sns os.chdir(r'D:\\projects\\wordpress\\ex185') os.getcwd() url = \"https:\/\/archive.ics.uci.edu\/ml\/machine-learning-databases\/auto-mpg\/auto-mpg.data\" df = pd.read_csv(url) column_names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'year', 'origin', 'name'] df = pd.read_csv(url, names= column_names, delim_whitespace=True) df.loc[df.horsepower == '?', 'horsepower'] =\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=654"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/654\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}