Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code a Python script that accomplishes the following -- Reads nics-firearm-background-checks.csv (https://drive.google.com/file/d/17B5ZrAakOQoeeuyJxzqUza0e-hQthY1f/view?usp=sharing) into a DataFrame called 'raw_frame.' From 'raw_frame,' extracts and transforms the data shown

Code a Python script that accomplishes the following --

  1. Reads nics-firearm-background-checks.csv (https://drive.google.com/file/d/17B5ZrAakOQoeeuyJxzqUza0e-hQthY1f/view?usp=sharing) into a DataFrame called 'raw_frame.'
  2. From 'raw_frame,' extracts and transforms the data shown below in columns A, B, E, and F, into a second DataFrame called 'transformed_frame.' The cells of 'transformed_frame' will need to contain permit application totals for state-year combinations, in separate columns for handgun permit applications and long gun permit applications, and in separate columns for each year in the range 2010-2020. Note that months will need to be aggregated into years. As a result of this and due to moving years from rows into columns, the total number of rows will shrink from more than 14,000 to fewer than 60.
  3. Converts 'transformed_frame' into a saved .csv file called transformed_frame_csv.csv. The column headings of this .csv file will need to be as shown in the second diagram below. You will submit this file together with the rest of your work.

The original nics-firearm-background-checks.csv file

image text in transcribedimage text in transcribed
A B C D E F G H J K M N month state permit permit_recheck handgun long_gun other multiple admin prepawn_handgun prepawn_long_gun prepawn_other redemption_handgun redemption_long_gun 2021-02 Alabama 31803 512 20970 16026 1548 959 0 18 14 1966 791 W 2021-02 Alaska 222 3055 2564 375 189 w 122 79 2021-02 Arizona 9290 1159 20530 9991 1754 1114 10 1059 404 0 00 O O 2021-02 Arkansas 3123 1152 7068 5289 448 390 7 13 771 623 2021-02 California 16025 11953 40789 27915 6499 0 IN 508 275 2021-02 Colorado 10891 6 21729 13839 1960 1760 O 0 0 00 2021-02 Connecticut 9792 476 6046 1996 1438 0 0 0 9 2021-02 Delaware 353 0 2775 1563 158 153 11 6 10 2021-02 District of Columbia 538 304 4 0 2 0 11 2021-02 Florida 31875 0 66307 26720 5116 2894 3162 776 12 2021-02 Georgia 37243 21523 10215 1122 727 1495 705 OOO OOO HOO O 13 2021-02 Guam 0 190 70 34 7 0 O 14 2021-02 Hawaii 1504 0 0 0 0 OH HO ONE NOHOHOO WOOOOOONWON 0 0 O O 15 2021-02 Idaho 6846 6973 5631 762 385 261 242 P O O O O D D W H NOW OOO UTOOOOO 16 2021-02 Illinois 18820 846252 24290 11338 0 1320 0 0 P O OOO VW VOW ONOOOOOOOOO 17 2021-02 Indiana 902 150662 25161 14378 2063 866 18 513 276 18 2021-02 lowa 15966 11779 204 2462 65 1 26 19 2021-02 Kansas 2083 7 7573 5810 865 430 453 201 20 2021-02 Kentucky 1304 352938 12171 8806 609 623 1223 730 21 2021-02 Louisiana 2435 204 13373 7560 1094 680 0 853 404 22 2021-02 Maine 678 6 4167 3357 416 215 52 41 23 2021-02 Mariana Islands 0 10 2 3 0 0 24 2021-02 Maryland 7561 26 9199 6777 136 10 OO OO N 46 73 25 2021-02 Massachusetts 11858 3 6856 3385 1181 288 7 4 26 2021-02 Michigan 21953 9059 28567 17556 2545 892 25 192 nics-firearm-background-checks + 4A B C D E F G H State Handgun permit apps 2010 Long gun permit apps 2010 Handgun permit apps 2011 Long gun permit apps 2011 Handgun permit apps 2012 Long gun permit apps 2012 Handgu IN 0 Alabama 116963 136519 130490 146290 177239 184072 W 1 Alaska 25720 33177 28291 34607 35851 40505 2 Arizona 89162 69067 108245 81285 139050 107079 UI A 3 Arkansas 49992 72206 54659 78806 69481 94539 4 California 245159 275458 303169 320988 375569 423207 5 Colorado 130155 129642 148975 146166 184989 170969 00 6 Connecticut 47545 40546 49793 41435 63570 53992 9 7 Delaware 9230 9466 11126 10672 15684 13873 10 8 District of Columbia 308 11 280 9 427 18 11 9 Florida 332371 186675 379889 212419 473185 296793 12 10 Georgia 99145 95541 116794 112097 149486 138183 13 11 Guam 240 268 231 242 411 448 14 12 Hawaii 0 0 0 0 2 2 15 13 Idaho 23081 42074 27967 47957 35429 57061 16 14 Illinois 109204 116746 134178 133935 181910 174405 17 15 Indiana 112615 114450 136250 130012 188980 174306 18 16 lowa 588 40400 995 41838 1473 45722 19 17 Kansas 57808 67562 60955 74165 82285 90441 20 18 Kentucky 84311 99910 92936 111518 117969 129589 21 19 Louisiana 89765 119251 101519 130125 129806 157772 22 20 Maine 23380 37968 27040 40838 36602 48634 23 21 Mariana Islands 0 0 0 5 24 22 Maryland 39909 45556 45851 53678 66909 65937 25 23 Massachusetts 33468 21903 42506 24802 55136 35033 26 24 Michigan 18523 129008 15224 134412 21005 159546 transformed_frame_csv +

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Unity From Zero To Proficiency Beginner A Step By Step Guide To Coding Your First Game

Authors: Patrick Felicia

1st Edition

1091872023, 978-1091872028

More Books

Students also viewed these Programming questions