Skip to content

Commit 0b714c4

Browse files
committed
fixed assignment 2 to increase accuracy
1 parent a446e70 commit 0b714c4

File tree

4 files changed

+220
-174
lines changed

4 files changed

+220
-174
lines changed

ClassNotebooks/.ipynb_checkpoints/Assignment 2-checkpoint.ipynb

+52-51
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
{
2525
"cell_type": "code",
26-
"execution_count": 45,
26+
"execution_count": 1,
2727
"metadata": {
2828
"collapsed": false,
2929
"nbgrader": {
@@ -183,7 +183,7 @@
183183
"Australasia 12 ANZ "
184184
]
185185
},
186-
"execution_count": 45,
186+
"execution_count": 1,
187187
"metadata": {},
188188
"output_type": "execute_result"
189189
}
@@ -225,7 +225,7 @@
225225
},
226226
{
227227
"cell_type": "code",
228-
"execution_count": 46,
228+
"execution_count": 2,
229229
"metadata": {
230230
"collapsed": false
231231
},
@@ -252,7 +252,7 @@
252252
"Name: Afghanistan, dtype: object"
253253
]
254254
},
255-
"execution_count": 46,
255+
"execution_count": 2,
256256
"metadata": {},
257257
"output_type": "execute_result"
258258
}
@@ -282,7 +282,7 @@
282282
},
283283
{
284284
"cell_type": "code",
285-
"execution_count": 47,
285+
"execution_count": 3,
286286
"metadata": {
287287
"collapsed": false,
288288
"nbgrader": {
@@ -298,7 +298,7 @@
298298
"'United States'"
299299
]
300300
},
301-
"execution_count": 47,
301+
"execution_count": 3,
302302
"metadata": {},
303303
"output_type": "execute_result"
304304
}
@@ -322,7 +322,7 @@
322322
},
323323
{
324324
"cell_type": "code",
325-
"execution_count": 66,
325+
"execution_count": 4,
326326
"metadata": {
327327
"collapsed": false
328328
},
@@ -333,7 +333,7 @@
333333
"'United States'"
334334
]
335335
},
336-
"execution_count": 66,
336+
"execution_count": 4,
337337
"metadata": {},
338338
"output_type": "execute_result"
339339
}
@@ -360,7 +360,7 @@
360360
},
361361
{
362362
"cell_type": "code",
363-
"execution_count": 67,
363+
"execution_count": 5,
364364
"metadata": {
365365
"collapsed": false
366366
},
@@ -371,7 +371,7 @@
371371
"'Bulgaria'"
372372
]
373373
},
374-
"execution_count": 67,
374+
"execution_count": 5,
375375
"metadata": {},
376376
"output_type": "execute_result"
377377
}
@@ -399,7 +399,7 @@
399399
},
400400
{
401401
"cell_type": "code",
402-
"execution_count": 72,
402+
"execution_count": 6,
403403
"metadata": {
404404
"collapsed": false
405405
},
@@ -412,38 +412,38 @@
412412
"Argentina 130\n",
413413
"Armenia 16\n",
414414
"Australasia 22\n",
415-
"Australia 919\n",
416-
"Austria 488\n",
415+
"Australia 923\n",
416+
"Austria 569\n",
417417
"Azerbaijan 43\n",
418418
"Bahamas 24\n",
419419
"Bahrain 1\n",
420420
"Barbados 1\n",
421-
"Belarus 149\n",
422-
"Belgium 273\n",
421+
"Belarus 154\n",
422+
"Belgium 276\n",
423423
"Bermuda 1\n",
424424
"Bohemia 5\n",
425425
"Botswana 2\n",
426426
"Brazil 184\n",
427427
"British West Indies 2\n",
428-
"Bulgaria 408\n",
428+
"Bulgaria 411\n",
429429
"Burundi 3\n",
430430
"Cameroon 12\n",
431-
"Canada 794\n",
431+
"Canada 846\n",
432432
"Chile 24\n",
433-
"China 1101\n",
433+
"China 1120\n",
434434
"Colombia 29\n",
435435
"Costa Rica 7\n",
436436
"Ivory Coast 2\n",
437-
"Croatia 66\n",
437+
"Croatia 67\n",
438438
"Cuba 420\n",
439439
"Cyprus 2\n",
440440
" ... \n",
441-
"Spain 267\n",
441+
"Spain 268\n",
442442
"Sri Lanka 4\n",
443443
"Sudan 2\n",
444444
"Suriname 4\n",
445-
"Sweden 1163\n",
446-
"Switzerland 582\n",
445+
"Sweden 1217\n",
446+
"Switzerland 630\n",
447447
"Syria 6\n",
448448
"Chinese Taipei 32\n",
449449
"Tajikistan 4\n",
@@ -455,30 +455,30 @@
455455
"Tunisia 19\n",
456456
"Turkey 191\n",
457457
"Uganda 14\n",
458-
"Ukraine 216\n",
458+
"Ukraine 220\n",
459459
"United Arab Emirates 3\n",
460-
"United States 5600\n",
460+
"United States 5684\n",
461461
"Uruguay 16\n",
462462
"Uzbekistan 38\n",
463463
"Venezuela 18\n",
464464
"Vietnam 4\n",
465465
"Virgin Islands 2\n",
466-
"Yugoslavia 170\n",
466+
"Yugoslavia 171\n",
467467
"Independent Olympic Participants 4\n",
468468
"Zambia 3\n",
469469
"Zimbabwe 18\n",
470470
"Mixed team 38\n",
471471
"Name: Points, dtype: int64"
472472
]
473473
},
474-
"execution_count": 72,
474+
"execution_count": 6,
475475
"metadata": {},
476476
"output_type": "execute_result"
477477
}
478478
],
479479
"source": [
480480
"def answer_four():\n",
481-
" df['Points'] = df['Gold.2'] * 3 + df['Silver.2'] * 2 + df['Bronze']\n",
481+
" df['Points'] = df['Gold.2'] * 3 + df['Silver.2'] * 2 + df['Bronze.2'] * 1\n",
482482
" return df['Points']\n",
483483
"\n",
484484
"answer_four()"
@@ -501,7 +501,7 @@
501501
},
502502
{
503503
"cell_type": "code",
504-
"execution_count": 148,
504+
"execution_count": 7,
505505
"metadata": {
506506
"collapsed": false
507507
},
@@ -702,7 +702,7 @@
702702
"[5 rows x 100 columns]"
703703
]
704704
},
705-
"execution_count": 148,
705+
"execution_count": 7,
706706
"metadata": {},
707707
"output_type": "execute_result"
708708
}
@@ -714,7 +714,7 @@
714714
},
715715
{
716716
"cell_type": "code",
717-
"execution_count": 182,
717+
"execution_count": 8,
718718
"metadata": {
719719
"collapsed": false
720720
},
@@ -725,7 +725,7 @@
725725
"'Texas'"
726726
]
727727
},
728-
"execution_count": 182,
728+
"execution_count": 8,
729729
"metadata": {},
730730
"output_type": "execute_result"
731731
}
@@ -749,27 +749,28 @@
749749
},
750750
{
751751
"cell_type": "code",
752-
"execution_count": 274,
752+
"execution_count": 9,
753753
"metadata": {
754754
"collapsed": false
755755
},
756756
"outputs": [
757757
{
758758
"data": {
759759
"text/plain": [
760-
"['California', 'Illinois', 'Texas']"
760+
"['California', 'Texas', 'Illinois']"
761761
]
762762
},
763-
"execution_count": 274,
763+
"execution_count": 9,
764764
"metadata": {},
765765
"output_type": "execute_result"
766766
}
767767
],
768768
"source": [
769769
"def answer_six():\n",
770-
" d = census_df.where(census_df['SUMLEV'] == 50)\n",
771-
" \n",
772-
" return d.groupby(['STNAME', 'COUNTY']).POPESTIMATE2015.max().nlargest(3).reset_index()['STNAME'].tolist()\n",
770+
" df1 = pd.DataFrame(census_df.where(census_df['SUMLEV'] == 50).groupby(['STNAME'])['POPESTIMATE2015'].nlargest(3))\n",
771+
" df1 = df1.reset_index()\n",
772+
"\n",
773+
" return list(df1.groupby(['STNAME']).sum()['POPESTIMATE2015'].nlargest(3).index)\n",
773774
"\n",
774775
"answer_six()"
775776
]
@@ -786,7 +787,7 @@
786787
},
787788
{
788789
"cell_type": "code",
789-
"execution_count": 316,
790+
"execution_count": 10,
790791
"metadata": {
791792
"collapsed": false,
792793
"scrolled": true
@@ -798,7 +799,7 @@
798799
"'Harris County'"
799800
]
800801
},
801-
"execution_count": 316,
802+
"execution_count": 10,
802803
"metadata": {},
803804
"output_type": "execute_result"
804805
}
@@ -829,7 +830,7 @@
829830
},
830831
{
831832
"cell_type": "code",
832-
"execution_count": 336,
833+
"execution_count": 13,
833834
"metadata": {
834835
"collapsed": false
835836
},
@@ -848,13 +849,13 @@
848849
" </thead>\n",
849850
" <tbody>\n",
850851
" <tr>\n",
851-
" <th>1211</th>\n",
852-
" <td>Maine</td>\n",
852+
" <th>896</th>\n",
853+
" <td>Iowa</td>\n",
853854
" <td>Washington County</td>\n",
854855
" </tr>\n",
855856
" <tr>\n",
856-
" <th>1918</th>\n",
857-
" <td>New York</td>\n",
857+
" <th>1419</th>\n",
858+
" <td>Minnesota</td>\n",
858859
" <td>Washington County</td>\n",
859860
" </tr>\n",
860861
" <tr>\n",
@@ -868,8 +869,8 @@
868869
" <td>Washington County</td>\n",
869870
" </tr>\n",
870871
" <tr>\n",
871-
" <th>2863</th>\n",
872-
" <td>Vermont</td>\n",
872+
" <th>3163</th>\n",
873+
" <td>Wisconsin</td>\n",
873874
" <td>Washington County</td>\n",
874875
" </tr>\n",
875876
" </tbody>\n",
@@ -878,22 +879,22 @@
878879
],
879880
"text/plain": [
880881
" STNAME CTYNAME\n",
881-
"1211 Maine Washington County\n",
882-
"1918 New York Washington County\n",
882+
"896 Iowa Washington County\n",
883+
"1419 Minnesota Washington County\n",
883884
"2345 Pennsylvania Washington County\n",
884885
"2355 Rhode Island Washington County\n",
885-
"2863 Vermont Washington County"
886+
"3163 Wisconsin Washington County"
886887
]
887888
},
888-
"execution_count": 336,
889+
"execution_count": 13,
889890
"metadata": {},
890891
"output_type": "execute_result"
891892
}
892893
],
893894
"source": [
894895
"def answer_eight():\n",
895896
"\n",
896-
" return census_df[((census_df['REGION'] == 1) | (census_df['REGION'] == 1)) & (census_df['CTYNAME'].str.startswith(\"Washington\"))].loc[:,['STNAME','CTYNAME']]\n",
897+
" return census_df[((census_df['REGION'] == 1) | (census_df['REGION'] == 2)) & (census_df['CTYNAME'].str.startswith(\"Washington\") & (census_df['POPESTIMATE2015'] > census_df['POPESTIMATE2014']))].loc[:,['STNAME','CTYNAME']]\n",
897898
"\n",
898899
"answer_eight()"
899900
]

0 commit comments

Comments
 (0)