Homework5: Pandas DataFrame Manipulation* Objective: To enhance a dataset and analyze it with Pandas DataFrame functions. Requirements: Write Python code to create a Pandas DataFrame with information...

1 answer below »
Using python notebook


Homework5: Pandas DataFrame Manipulation* Objective: To enhance a dataset and analyze it with Pandas DataFrame functions. Requirements: Write Python code to create a Pandas DataFrame with information about each one of the fifty states in the U.S. Start by downloading the .csv or .json file from https://worldpopulationreview.com/states (You need to scroll down to see the download button for the datafile). 1. Read the file into your Python program and use web scraping code to add the region to each state according to: https://www.50states.com/city/regions.htm. 2. The expanded DataFrame should have one additional column showing the region for each state. 3. Save your DataFrame in a csv file and print the first few rows to show that it is complete. 4. Then, run a pivot table to show the average density by region, and choose the right graph to show the average population by region. Analyze your results by writing a paragraph in your Word document with the screenshots. Code Documentation: You should also include other comments in your program explaining your code, variable names, or approaches. Submit for grading: Upload a plain text file (.txt) with your documented Python code. Do not include partial results on this file. You should also submit a Word document with screenshots of Jupyter notebook runs and the csv file where you saved the expanded DataFrame. Grading Rubric: 30% independent verification of program run; 30% required and correct output; 30% file submission compliance; 10% authorship, code and output documentation.
Answered 4 days AfterMay 01, 2021

Answer To: Homework5: Pandas DataFrame Manipulation* Objective: To enhance a dataset and analyze it with Pandas...

Sandeep Kumar answered on May 06 2021
146 Votes
states.ipynb
{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python385jvsc74a57bd0916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1",
"display_name": "Python 3.8.5 64-bit"
},
"metadata": {
"interpreter": {
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
}
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"cell_type": "code",
"execution_count": 180,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from bs4 import BeautifulSoup\n",
"from urllib.request import urlopen, Request\n",
"import pandas as pd\n",
"import re\n"
]
},
{
"cell_type": "code",
"execution_count": 244,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('cs
vData.csv')\n"
]
},
{
"cell_type": "code",
"execution_count": 245,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" rank State Pop Growth Pop2018 Pop2010 \\\n",
"0 1 California 39613500 0.0038 39461600 37319500 \n",
"1 2 Texas 29730300 0.0385 28628700 25242000 \n",
"2 3 Florida 21944600 0.0330 21244300 18845500 \n",
"3 4 New York 19300000 -0.0118 19530400 19399900 \n",
"4 5 Pennsylvania 12804100 0.0002 12800900 12711200 \n",
"5 6 Illinois 12569300 -0.0121 12723100 12840500 \n",
"6 7 Ohio 11714600 0.0033 11676300 11539300 \n",
"7 8 Georgia 10830000 0.0303 10511100 9711880 \n",
"8 9 North Carolina 10701000 0.0308 10381600 9574320 \n",
"9 10 Michigan 9992430 0.0008 9984070 9877510 \n",
"10 11 New Jersey 8874520 -0.0013 8886020 8799450 \n",
"11 12 Virginia 8603980 0.0121 8501290 8023700 \n",
"12 13 Washington 7796940 0.0363 7523870 6742830 \n",
"13 14 Arizona 7520100 0.0506 7158020 6407170 \n",
"14 15 Tennessee 6944260 0.0255 6771630 6355310 \n",
"15 16 Massachusetts 6912240 0.0043 6882640 6566310 \n",
"16 17 Indiana 6805660 0.0165 6695500 6490430 \n",
"17 18 Missouri 6169040 0.0077 6121620 5995970 \n",
"18 19 Maryland 6065440 0.0049 6035800 5788640 \n",
"19 20 Colorado 5893630 0.0356 5691290 5047350 \n",
"20 21 Wisconsin 5852490 0.0078 5807410 5690480 \n",
"21 22 Minnesota 5706400 0.0179 5606250 5310830 \n",
"22 23 South Carolina 5277830 0.0381 5084160 4635650 \n",
"23 24 Alabama 4934190 0.0095 4887680 4785440 \n",
"24 25 Louisiana 4627000 -0.0070 4659690 4544530 \n",
"25 26 Kentucky 4480710 0.0044 4461150 4348180 \n",
"26 27 Oregon 4289440 0.0257 4181890 3837490 \n",
"27 28 Oklahoma 3990440 0.0127 3940240 3759940 \n",
"28 29 Connecticut 3552820 -0.0052 3571520 3579110 \n",
"29 30 Utah 3310770 0.0499 3153550 2775330 \n",
"30 31 Puerto Rico 3194370 0.0003 3193350 3721520 \n",
"31 32 Nevada 3185790 0.0523 3027340 2702400 \n",
"32 33 Iowa 3167970 0.0061 3148620 3050740 \n",
"33 34 Arkansas 3033950 0.0080 3009730 2921960 \n",
"34 35 Mississippi 2966410 -0.0049 2981020 2970550 \n",
"35 36 Kansas 2917220 0.0020 2911360 2858190 \n",
"36 37 New Mexico 2105000 0.0059 2092740 2064550 \n",
"37 38 Nebraska 1952000 0.0137 1925610 1829540 \n",
"38 39 Idaho 1860120 0.0626 1750540 1570750 \n",
"39 40 West Virginia 1767860 -0.0202 1804290 1854240 \n",
"40 41 Hawaii 1406430 -0.0100 1420590 1363960 \n",
"41 42 New Hampshire 1372200 0.0138 1353460 1316760 \n",
"42 43 Maine 1354520 0.0115 1339060 1327630 \n",
"43 44 Montana 1085000 0.0229 1060660 990697 \n",
"44 45 Rhode Island 1061510 0.0030 1058290 1053960 \n",
"45 46 Delaware 990334 0.0257 965479 899593 \n",
"46 47 South Dakota 896581 0.0204 878698 816166 \n",
"47 48 North Dakota 770026 0.0158 758080 674715 \n",
"48 49 Alaska 724357 -0.0147 735139 713910 \n",
"49 50 District of Columbia 714153 0.0180 701547 605226 \n",
"50 51 Vermont 623251 -0.0018 624358 625879 \n",
"51 52 Wyoming 581075 0.0060 577601 564487 \n",
"\n",
" growthSince2010 Percent density \n",
"0 0.0615 0.1184 254.2929 \n",
"1 0.1778 0.0889 113.8080 \n",
"2 0.1644 0.0656 409.2233 \n",
"3 -0.0051 0.0577 409.5404 \n",
"4 0.0073 0.0383 286.1699 \n",
"5 -0.0211 0.0376 226.3964 \n",
"6 0.0152 0.0350 286.6939 \n",
"7 0.1151 0.0324 188.3053 \n",
"8 0.1177 0.0320 220.1037 \n",
"9 0.0116 0.0299 176.7352 \n",
"10 0.0085 0.0265 1206.7609 \n",
"11 0.0723 0.0257 217.8774 \n",
"12 0.1563 0.0233 117.3248 \n",
"13 0.1737 0.0225 66.2016 \n",
"14 0.0927 0.0208 168.4069 \n",
"15 0.0527 0.0207 886.1846 \n",
"16 0.0486 0.0203 189.9643 \n",
"17 0.0289 0.0184 89.7419 \n",
"18 0.0478 0.0181 624.8522 \n",
"19 0.1677 0.0176 56.8653 \n",
"20 0.0285 0.0175 108.0633 \n",
"21 0.0745 0.0171 71.6641 \n",
"22 0.1385 0.0158 175.5707 \n",
"23 0.0311 0.0147 97.4270 \n",
"24 0.0181 0.0138 107.0966 \n",
"25 0.0305 0.0134 113.4759 \n",
"26 0.1178 0.0128 44.6873 \n",
"27 0.0613 0.0119 58.1739 \n",
"28 -0.0073 0.0106 733.7505 \n",
"29 0.1929 0.0099 40.2917 \n",
"30 -0.1416 0.0095 923.4952 \n",
"31 0.1789 0.0095 29.0195 \n",
"32 0.0384 0.0095 56.7157 \n",
"33 0.0383 0.0091 58.3059 \n",
"34 -0.0014 0.0089 63.2187 \n",
"35 0.0207 0.0087 35.6807 \n",
"36 0.0196 0.0063 17.3540 \n",
"37 0.0669 0.0058 25.4087 \n",
"38 0.1842 0.0056 22.5079 \n",
"39 -0.0466 0.0053 73.5444 \n",
"40 0.0311 0.0042 218.9678 \n",
"41 0.0421 0.0041 153.2671 \n",
"42 0.0203 0.0040 43.9166 \n",
"43 0.0952 0.0032 7.4547 \n",
"44 0.0072 0.0032 1026.6054 \n",
"45 0.1009 0.0030 508.1242 \n",
"46 0.0985 0.0027 11.8265 \n",
"47 0.1413 0.0023 11.1596 \n",
"48 0.0146 0.0022 1.2694 \n",
"49 0.1800 0.0021 11707.4262 \n",
"50 -0.0042 0.0019 67.6197 \n",
"51 0.0294 0.0017 5.9847 "
],
"text/html": "
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
rankStatePopGrowthPop2018Pop2010growthSince2010Percentdensity
01California396135000.003839461600373195000.06150.1184254.2929
12Texas297303000.038528628700252420000.17780.0889113.8080
23Florida219446000.033021244300188455000.16440.0656409.2233
34New York19300000-0.01181953040019399900-0.00510.0577409.5404
45Pennsylvania128041000.000212800900127112000.00730.0383286.1699
56Illinois12569300-0.01211272310012840500-0.02110.0376226.3964
67Ohio117146000.003311676300115393000.01520.0350286.6939
78Georgia108300000.03031051110097118800.11510.0324188.3053
89North...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here