-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalProject_Code_v1
More file actions
1212 lines (822 loc) · 37.2 KB
/
FinalProject_Code_v1
File metadata and controls
1212 lines (822 loc) · 37.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
######################################################################################################################
#Import packages
######################################################################################################################
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
######################################################################################################################
#Import Data from Excel
######################################################################################################################
#1. Import data
file='WDIW Dataset.xlsx'
worldData_df=pd.read_excel(file, index_col=0)
#CountryCode = 'CountryCode'
CountryName = 'CountryName'
HultRegion = 'Hult Region'
CoolName = 'Cool Name'
ElectricityAccessTotal = 'ElectricityAccessTotal'
ElectricityRuralAccess = 'ElectricityRuralAccess'
ElectricityUrbanAccess = 'ElectricityUrbanAccess'
AdolescentFertility = 'AdolescentFertility'
AgeDependencyTotal = 'AgeDependencyTotal'
AgeDependencyOld = 'AgeDependencyOld'
AgeDependencyYoung = 'AgeDependencyYoung'
GDP_AgriForFish = 'GDP_PrimaryActivities'
ArmedForces = 'ArmedForces'
BirthRate = 'BirthRate'
BirthSkilledStaff = 'BirthSkilledStaff'
DeathRate = 'DeathRate'
EducationPHD = 'EducationPHD'
EducationBachelor = 'EducationBachelor'
EducationMaster = 'EducationMaster'
EducationLowerSecondary = 'EducationLowerSecondary'
EducationPostSecondary = 'EducationPostSecondary'
EducationPrimary = 'EducationPrimary'
EducationTertiary = 'EducationTertiary'
EducationUpperSecondary = 'EducationUpperSecondary'
EmploymentAgriculture = 'EmploymentAgriculture'
EmploymentIndustry = 'EmploymentIndustry'
EmploymentServices = 'EmploymentServices'
FertilityRate = 'FertilityRate'
GDP = 'GDP'
GDPGrowth = 'GDPGrowth'
GINI = 'GINI'
ExpendEducation = 'ExpendEducation'
IncomeFourth = 'IncomeFourth'
IncomeFifth = 'IncomeFifth'
IncomeFirst = 'IncomeFirst'
IncomeSecond = 'IncomeSecond'
IncomeThird = 'IncomeThird'
GDP_Industry = 'GDP_Industry'
LifeExpectancy = 'LifeExpectancy'
LiteracyAdult = 'LiteracyAdult'
LiteracyYouth = 'LiteracyYouth'
GDP_Merchandise = 'GDP_Merchandise'
ExpendMilitary = 'ExpendMilitary'
MobileSubs = 'MobileSubs'
PovertyByHealthcare = 'PovertyByHealthcare'
Population0_14 = 'Population0_14'
Population15_64 = 'Population15_64'
Population65 = 'Population65+'
PopulationDensity = 'PopulationDensity'
PopulationGrowth = 'PopulationGrowth'
PopulationLargestCity = 'PopulationLargestCity'
PopulationSlums = 'PopulationSlums'
PopulationFemale = 'PopulationFemale'
PopulationMale = 'PopulationMale'
PopulationTotal = 'PopulationTotal'
Poverty_1 = 'Poverty_1.90'
Poverty_3 = 'Poverty_3.20'
Poverty_NationalLine = 'Poverty_NationalLine'
HIV = 'HIV'
Undernourishment = 'Undernourishment'
Underweight = 'Underweight'
PopulationRural = 'PopulationRural'
GDP_Services = 'GDP_Services'
SurfaceArea = 'SurfaceArea'
TaxRevenue = 'TaxRevenue'
PopulationUrban = 'PopulationUrban'
PopulationUrbanGrowth = 'PopulationUrbanGrowth'
newColumns=[#CountryCode,
CountryName, HultRegion, CoolName, ElectricityAccessTotal, ElectricityRuralAccess,\
ElectricityUrbanAccess, AdolescentFertility, AgeDependencyTotal, AgeDependencyOld, AgeDependencyYoung, GDP_AgriForFish,\
ArmedForces, BirthRate, BirthSkilledStaff, DeathRate, EducationPHD, EducationBachelor, \
EducationMaster, EducationLowerSecondary, EducationPostSecondary, EducationPrimary, EducationTertiary, EducationUpperSecondary,\
EmploymentAgriculture, EmploymentIndustry, EmploymentServices, FertilityRate, GDP, GDPGrowth,\
GINI, ExpendEducation, IncomeFourth, IncomeFifth, IncomeFirst, IncomeSecond,\
IncomeThird, GDP_Industry, LifeExpectancy, LiteracyAdult, LiteracyYouth, GDP_Merchandise,\
ExpendMilitary, MobileSubs, PovertyByHealthcare, Population0_14, Population15_64, Population65,\
PopulationDensity, PopulationGrowth, PopulationLargestCity, PopulationSlums, PopulationFemale, PopulationMale,\
PopulationTotal, Poverty_1, Poverty_3, Poverty_NationalLine, HIV, Undernourishment,\
Underweight, PopulationRural, GDP_Services, SurfaceArea, TaxRevenue, PopulationUrban,\
PopulationUrbanGrowth]
worldData_df.columns = newColumns
#2. Creation of the subset for Eastern Europe
teamData_df=worldData_df[worldData_df['Cool Name']=='Skids & Mudflap']
#3. Eliminating Andorra and San Marino
teamDataCleaned_df=teamData_df.copy()
teamDataCleaned_df=teamDataCleaned_df.drop(labels=['AND','SMR'])
######################################################################################################################
#Data Analysis
######################################################################################################################
#1. Adolescent Fertility
print(teamData_df['AdolescentFertility'].describe())
print('\n')
print(worldData_df['AdolescentFertility'][worldData_df['CountryName']=='World'])
#Histogram with missing values
teamData_df.hist(column=['AdolescentFertility'], bins='sturges')
plt.title('Eastern Europe')
plt.xlabel('Adolescent Fertility')
plt.show()
#The distribution is somewhat normal so we will use the mean for completing Kosovo
adolescentFertility_mean = teamDataCleaned_df['AdolescentFertility'].mean()
teamDataCleaned_df[['AdolescentFertility']] = teamDataCleaned_df[['AdolescentFertility']].fillna(adolescentFertility_mean)
print(teamDataCleaned_df['AdolescentFertility'].describe())
print(worldData_df['AdolescentFertility'][worldData_df['CountryName']=='World'])
sns.distplot(teamDataCleaned_df['AdolescentFertility'], bins='sturges')
plt.title('Eastern Europe')
plt.xlabel("AdolescentFertility")
plt.show()
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['AdolescentFertility'])
plt.title('AdolescentFertility')
plt.xticks(rotation=90)
plt.show()
#2. Age Dependecy Total
#We use the median of balcanic countries to fill Kosovo
ageDependency_median=teamDataCleaned_df.loc[['BIH','HRV','SVN','ALB','SRB','MKD','MNE'],['AgeDependencyTotal']].median()
teamDataCleaned_df[['AgeDependencyTotal']] = teamDataCleaned_df[['AgeDependencyTotal']].fillna(ageDependency_median)
#Description of the variable and World average
print(teamDataCleaned_df['AgeDependencyTotal'].describe())
print('\n')
print(worldData_df['AgeDependencyTotal'][worldData_df['CountryName']=='World'])
#Bar chat
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['AgeDependencyTotal'])
plt.title('Age Dependency Total')
plt.xticks(rotation=90)
plt.show()
#Histogram for Eastern Europe
teamDataCleaned_df.hist(column=['AgeDependencyTotal'], bins='sturges')
plt.title('Eastern Europe')
plt.xlabel('Age Dependency Total')
plt.show()
#Histogram for Western Europe
worldData_df['AgeDependencyTotal'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('Age Dependency Total')
plt.show()
#Histogram for the Rest of the World (Complement for Eastern Europe only)
worldData_df['AgeDependencyTotal'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('Age Dependency Total')
plt.show()
#3. Age Dependency Old
#We use the median of balcanic countries to fill Kosovo
ageDependencyOld_median=teamDataCleaned_df.loc[['BIH','HRV','SVN','ALB','SRB','MKD','MNE'],['AgeDependencyOld']].median()
teamDataCleaned_df[['AgeDependencyOld']] = teamDataCleaned_df[['AgeDependencyOld']].fillna(ageDependencyOld_median)
#Description of the variable and World average
print(teamDataCleaned_df['AgeDependencyOld'].describe())
print('\n')
print(worldData_df['AgeDependencyOld'][worldData_df['CountryName']=='World'])
#Bar chat
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['AgeDependencyOld'])
plt.title('Age Dependency Old')
plt.xticks(rotation=90)
plt.show()
#Histogram for Eastern Europe
teamData_df.hist(column=['AgeDependencyOld'], bins='sturges')
plt.title('Eastern Europe')
plt.xlabel('Age Dependency Old')
plt.show()
#Histogram for Western Europe
worldData_df['AgeDependencyOld'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('Age Dependency Old')
plt.show()
#Histogram for the Rest of the World (Complement for Eastern Europe only)
worldData_df['AgeDependencyOld'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('Age Dependency Old')
plt.show()
#4. Age Dependency Young
#We use the median of balcanic countries to fill Kosovo
ageDependencyOld_median=teamDataCleaned_df.loc[['BIH','HRV','SVN','ALB','SRB','MKD','MNE'],['AgeDependencyYoung']].median()
teamDataCleaned_df[['AgeDependencyYoung']] = teamDataCleaned_df[['AgeDependencyYoung']].fillna(ageDependencyOld_median)
#Description of the variable and World average
print(teamDataCleaned_df['AgeDependencyYoung'].describe())
print('\n')
print(worldData_df['AgeDependencyYoung'][worldData_df['CountryName']=='World'])
#Bar chat
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['AgeDependencyYoung'])
plt.title('Age Dependency Young')
plt.xticks(rotation=90)
plt.show()
#Histogram for Eastern Europe
teamData_df.hist(column=['AgeDependencyYoung'], bins='sturges')
plt.title('Eastern Europe')
plt.xlabel('Age Dependency Young')
plt.show()
#Histogram for Western Europe
worldData_df['AgeDependencyYoung'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('Age Dependency Young')
plt.show()
#Histogram for the Rest of the World (Complement for Eastern Europe only)
worldData_df['AgeDependencyOld'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('Age Dependency Old')
plt.show()
#5. GDP Primary Activities
#We fill the missing value of Poland with data from CIA
teamDataCleaned_df.loc['POL','GDP_PrimaryActivities']=2.7
#Description of the variable and World average
print(teamDataCleaned_df['GDP_PrimaryActivities'].describe())
print('\n')
print(worldData_df['GDP_PrimaryActivities'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['GDP_PrimaryActivities'])
plt.title('GDP_PrimaryActivities')
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['GDP_PrimaryActivities'])
plt.show()
#Clear outlier: Albania
#6. Birth Rate
#Description of the variable and World average
print(teamDataCleaned_df['BirthRate'].describe())
print('\n')
print(worldData_df['BirthRate'][worldData_df['CountryName']=='World'])
#Bar Chart with raw values
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['BirthRate'])
plt.title('BirthRate')
plt.xticks(rotation=90)
plt.show()
#We create a new variable that converts the birth rate to proportion of the population
teamDataCleaned_df['BirthRateProportion']=teamDataCleaned_df['BirthRate']*1000*100/teamDataCleaned_df['PopulationTotal']
#Bar chart with the new variable
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['BirthRateProportion'])
plt.xticks(rotation=90)
plt.title('BirthRateProportion')
plt.show()
#7. Death Rate
#Description of the variable and World average
print(teamDataCleaned_df['DeathRate'].describe())
print('\n')
print(worldData_df['DeathRate'][worldData_df['CountryName']=='World'])
#We create a new variable that converts the death rate to proportion of the population
teamDataCleaned_df['DeathRateProportion']=teamDataCleaned_df['DeathRate']*1000*100/teamDataCleaned_df['PopulationTotal']
#Bar Chart with raw values
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['DeathRate'])
plt.title('DeathRate')
plt.xticks(rotation=90)
plt.show()
#Bar chart with the new variable
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['DeathRateProportion'])
plt.title('DeathRateProportion')
plt.xticks(rotation=90)
plt.show()
#8. Population Total
#Description of the variable and World average
print(teamData_df['PopulationTotal'].describe())
print('\n')
print(worldData_df['PopulationTotal'][worldData_df['CountryName']=='World'])
#Bar Chart
plt.bar(x=teamData_df.index, height=teamData_df['PopulationTotal'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamData_df.hist(column=['PopulationTotal'], bins='sturges')
plt.show()
#9. Male Proportion
#We convert male population in another variable called Male Proportion
teamDataCleaned_df['MaleProportion']=pd.DataFrame(teamData_df['PopulationMale']/teamData_df['PopulationTotal'])
#We complete the missing value for Kosovo with the median
maleProportion_median = teamDataCleaned_df['MaleProportion'].median()
teamDataCleaned_df[['MaleProportion']] = teamDataCleaned_df[['MaleProportion']].fillna(maleProportion_median)
#We complete Male Population for Kosovo
teamDataCleaned_df.loc['XKX','PopulationMale']=round(teamDataCleaned_df.loc['XKX','PopulationTotal']*teamDataCleaned_df.loc['XKX','MaleProportion'])
#Bar chart for Male Proportion
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['MaleProportion'])
plt.xticks(rotation=90)
plt.show()
#Histogram for Male Proportion
teamDataCleaned_df.hist(column=['MaleProportion'], bins='sturges')
plt.show()
#10. Female Proportion
#We convert female population in another variable called Female Proportion
teamDataCleaned_df['FemaleProportion']=pd.DataFrame(teamData_df['PopulationFemale']/teamData_df['PopulationTotal'])
#We complete the missing value for Kosovo with the median
femaleProportion_median = teamDataCleaned_df['FemaleProportion'].median()
teamDataCleaned_df[['FemaleProportion']] = teamDataCleaned_df[['FemaleProportion']].fillna(femaleProportion_median)
#We complete Female Population for Kosovo
teamDataCleaned_df.loc['XKX','PopulationFemale']=round(teamDataCleaned_df.loc['XKX','PopulationTotal']*teamDataCleaned_df.loc['XKX','FemaleProportion'])
#Bar chart for Female Proportion
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['FemaleProportion'])
plt.xticks(rotation=90)
plt.show()
#Histogram for Female Proportion
teamDataCleaned_df.hist(column=['FemaleProportion'], bins='sturges')
plt.show()
#11. Population Slums
#Description of the variable and World average
print(teamDataCleaned_df['PopulationSlums'].describe())
print('\n')
print(worldData_df['PopulationSlums'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['PopulationSlums'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['PopulationSlums'], bins='sturges')
plt.show()
#12. Population Largest City
#We fill the missing values with data found on research and the median for Kosovo
teamDataCleaned_df.loc['MLT','PopulationLargestCity']= 5
teamDataCleaned_df.loc['MNE','PopulationLargestCity']= 42.8
teamDataCleaned_df.loc['SVN','PopulationLargestCity']= 25.7
Kosovomedcity = teamDataCleaned_df['PopulationLargestCity'].median()
teamDataCleaned_df[['PopulationLargestCity']] = teamDataCleaned_df[['PopulationLargestCity']].fillna(Kosovomedcity)
#Description of the variable and World average
print(teamDataCleaned_df['PopulationLargestCity'].describe())
print('\n')
print(worldData_df['PopulationLargestCity'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['PopulationLargestCity'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['PopulationLargestCity'], bins='sturges')
plt.show()
#13. Employment Agriculture
#We fill the missing value with the median
EmploymentAgriculture_median = teamDataCleaned_df['EmploymentAgriculture'].median()
teamDataCleaned_df[['EmploymentAgriculture']] = teamDataCleaned_df[['EmploymentAgriculture']].fillna(EmploymentAgriculture_median)
#Description of the variable and World average
print(teamDataCleaned_df['EmploymentAgriculture'].describe())
print('\n')
print(worldData_df['EmploymentAgriculture'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['EmploymentAgriculture'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['EmploymentAgriculture'], bins='sturges')
plt.show()
#Adding histograms for Western Europe and the Rest of the World
worldData_df['EmploymentAgriculture'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('EmploymentAgriculture')
plt.show()
worldData_df['EmploymentAgriculture'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('EmploymentAgriculture')
plt.show()
#14. Employment Industry
#We fill the missing value with the median
EmploymentIndustry_median = teamDataCleaned_df['EmploymentIndustry'].median()
teamDataCleaned_df[['EmploymentIndustry']] = teamDataCleaned_df[['EmploymentIndustry']].fillna(EmploymentIndustry_median)
#Description of the variable and World average
print(teamDataCleaned_df['EmploymentIndustry'].describe())
print('\n')
print(worldData_df['EmploymentIndustry'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['EmploymentIndustry'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['EmploymentIndustry'], bins='sturges')
plt.show()
#Adding histograms for Western Europe and the Rest of the World
worldData_df['EmploymentIndustry'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('EmploymentIndustry')
plt.show()
worldData_df['EmploymentIndustry'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('EmploymentIndustry')
plt.show()
#15. Employment Services
#We fill the missing value with the median
EmploymentServices_median = teamDataCleaned_df['EmploymentServices'].median()
teamDataCleaned_df[['EmploymentServices']] = teamDataCleaned_df[['EmploymentServices']].fillna(EmploymentServices_median)
#Description of the variable and World average
print(teamDataCleaned_df['EmploymentServices'].describe())
print('\n')
print(worldData_df['EmploymentServices'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['EmploymentServices'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['EmploymentServices'], bins='sturges')
plt.show()
#Adding histograms for Western Europe and the Rest of the World
worldData_df['EmploymentServices'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('EmploymentServices')
plt.show()
worldData_df['EmploymentServices'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('EmploymentServices')
plt.show()
#16. Employment Distribution (graph only)
#Define graph size
plt.figure(figsize =(12, 8))
#Create Agriculture bar
plt.barh(y=teamDataCleaned_df.index, width=teamDataCleaned_df['EmploymentAgriculture'], color='#b5ffb9')
#Create Industry Bar
plt.barh(y=teamDataCleaned_df.index, width=teamDataCleaned_df['EmploymentIndustry'], color='#f9bc86', edgecolor='white', left=teamDataCleaned_df['EmploymentAgriculture'])
#Create Services Bar
plt.barh(y=teamDataCleaned_df.index, width=teamDataCleaned_df['EmploymentServices'], color='#a3acff', edgecolor='white', left=(teamDataCleaned_df['EmploymentAgriculture']+teamDataCleaned_df['EmploymentIndustry']))
#Set legend
legend=['Agriculture','Industry','Services']
plt.legend(legend)
plt.show()
#17. Fertility Rate
#Description of the variable and World average
print(teamDataCleaned_df['FertilityRate'].describe())
print('\n')
print(worldData_df['FertilityRate'][worldData_df['CountryName']=='World'])
#Bar Chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['FertilityRate'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['FertilityRate'], bins='sturges')
plt.show()
#Adding histograms for Western Europe and the Rest of the World
worldData_df['FertilityRate'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('FertilityRate')
plt.show()
worldData_df['FertilityRate'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('FertilityRate')
plt.show()
#18. GDP and GDP per Capita
#Calculation of GDP per Capita
teamDataCleaned_df['GDPCapita']=pd.DataFrame(teamData_df['GDP']/teamData_df['PopulationTotal'])
#Bar chart for GDP
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['GDP'])
plt.title('GDP')
plt.xticks(rotation=90)
plt.show()
#Histogram for GDP
teamDataCleaned_df.hist(column=['GDP'], bins='sturges')
plt.title('GDP')
plt.show()
#Bar chart for GDP per Capita
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['GDPCapita'])
plt.title('GDP per Capita')
plt.xticks(rotation=90)
plt.show()
#Histogram for GDP
teamDataCleaned_df.hist(column=['GDPCapita'], bins='sturges')
plt.title('GDP per Capita')
plt.show()
#19. GDP Growth
#Description of the variable and World average
print(teamDataCleaned_df['GDPGrowth'].describe())
print('\n')
print(worldData_df['GDPGrowth'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamData_df.index, height=teamData_df['GDPGrowth'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamData_df.hist(column=['GDPGrowth'], bins='sturges')
plt.show()
#Adding histograms for Western Europe and the Rest of the World
worldData_df['GDPGrowth'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('GDPGrowth')
plt.show()
worldData_df['GDPGrowth'][worldData_df['CountryName']!='World'][worldData_df['Cool Name']!='Skids & Mudflap'].hist(bins='sturges')
plt.title('Rest of the World')
plt.xlabel('GDPGrowth')
plt.show()
#20. GDP Services
#We complete the data for Poland found on research
teamDataCleaned_df.loc['POL','GDP_Services']= 58.9
#Description of the variable and World average
print(teamDataCleaned_df['GDP_Services'].describe())
print('\n')
print(worldData_df['GDP_Services'][worldData_df['CountryName']=='World'])
#Bar Chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['GDP_Services'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['GDP_Services'], bins='sturges')
plt.show()
#Histogram for Western Europe
worldData_df['GDP_Services'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('GDP_Services')
plt.show()
#21. Armed Forces
#Kosovo officially announced an army on 2018, therefore it should be zero
teamDataCleaned_df['ArmedForces'] = teamDataCleaned_df['ArmedForces'].fillna(0)
#Description of the variable and World average
print(teamDataCleaned_df['ArmedForces'].describe())
print('\n')
print(worldData_df['ArmedForces'][worldData_df['CountryName']=='World'])
#Bar Chart
plt.title('Armed Forces - % of Total labor force')
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['ArmedForces'])
plt.xticks(ticks=teamDataCleaned_df.index, labels=teamDataCleaned_df['CountryName'],rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['ArmedForces'], bins='sturges')
plt.show()
#Seaborn plot
sns.distplot(teamDataCleaned_df['ArmedForces'], bins='sturges')
plt.title("Armed Forces - % of total labor force - Seaborn")
plt.show()
#22. GDP Industry
#First we complete Poland's GDP Industry from research
teamDataCleaned_df.loc['POL','GDP_Industry']= 38.4
#Description of the variable and World average
print(teamDataCleaned_df['GDP_Industry'].describe())
print('\n')
print(worldData_df['GDP_Industry'][worldData_df['CountryName']=='World'])
#X-bar plot - Filled the gaps
plt.title('Industry (% of GDP)')
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['GDP_Industry'])
plt.xticks(ticks=teamDataCleaned_df.index, labels=teamDataCleaned_df['CountryName'],rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['GDP_Industry'], bins='sturges')
plt.show()
#Seaborn plot
sns.distplot(teamDataCleaned_df['GDP_Industry'], bins='sturges')
plt.title("Industry (% of GDP) - Seaborn")
plt.show()
#23. GDP Composition (graph only)
#Define graph size
plt.figure(figsize =(12, 8))
#Create Agriculture bar
plt.barh(y=teamDataCleaned_df.index, width=teamDataCleaned_df['GDP_PrimaryActivities'], color='#b5ffb9')
#Create Industry Bar
plt.barh(y=teamDataCleaned_df.index, width=teamDataCleaned_df['GDP_Industry'], color='#f9bc86', edgecolor='white', left=teamDataCleaned_df['GDP_PrimaryActivities'])
#Create Services Bar
plt.barh(y=teamDataCleaned_df.index, width=teamDataCleaned_df['GDP_Services'], color='#a3acff', edgecolor='white', left=(teamDataCleaned_df['GDP_PrimaryActivities']+teamDataCleaned_df['GDP_Industry']))
#Set legend
legend=['Agriculture','Industry','Services']
plt.legend(legend)
plt.title('GDP Composition')
plt.show()
#24. Life Expectancy
#Description of the variable and World average
print(teamDataCleaned_df['LifeExpectancy'].describe())
print('\n')
print(worldData_df['LifeExpectancy'][worldData_df['CountryName']=='World'])
#X-bar plot
plt.title('Life Expectancy at Birth (in years)')
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['LifeExpectancy'])
plt.xticks(ticks=teamDataCleaned_df.index, labels=teamDataCleaned_df['CountryName'],rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['LifeExpectancy'], bins='sturges')
plt.show()
#Histogram for Western Europe
worldData_df['LifeExpectancy'][worldData_df['Cool Name']=='Jetfire'].hist(bins='sturges')
plt.title('Western Europe')
plt.xlabel('LifeExpectancy')
plt.show()
#25. GDP Merchandise
#We fill the missing value for Kosovo with the mean of the lowest countries
GDPMerch_mean = teamDataCleaned_df.loc[['FIN','GRC','NOR','SWE'],'GDP_Merchandise'].mean()
teamDataCleaned_df['GDP_Merchandise'] = teamDataCleaned_df['GDP_Merchandise'].fillna(GDPMerch_mean)
#Description of the variable and World average
print(teamDataCleaned_df['GDP_Merchandise'].describe())
print('\n')
print(worldData_df['GDP_Merchandise'][worldData_df['CountryName']=='World'])
#X-bar plot
plt.title('Merchandise Trade (% of GDP)')
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['GDP_Merchandise'])
plt.xticks(ticks=teamDataCleaned_df.index, labels=teamDataCleaned_df['CountryName'],rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['GDP_Merchandise'], bins='sturges')
plt.show()
#Seaborn plot
sns.distplot(teamDataCleaned_df['GDP_Merchandise'], bins='sturges')
plt.title("Merchandise Trade (% of GDP) - Seaborn")
plt.show()
#26. Military Expenditures
#Description of the variable and World average
print(teamDataCleaned_df['ExpendMilitary'].describe())
print('\n')
print(worldData_df['ExpendMilitary'][worldData_df['CountryName']=='World'])
#X-bar plot
plt.title('Military Expenditure( % of GDP)')
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['ExpendMilitary'])
plt.xticks(ticks=teamDataCleaned_df.index, labels=teamDataCleaned_df['CountryName'],rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['ExpendMilitary'], bins='sturges')
plt.show()
#Seaborn plot
sns.distplot(teamDataCleaned_df['ExpendMilitary'], bins='sturges')
plt.title("Military Expenditure( % of GDP) - Seaborn")
plt.show()
#27. Mobile Subscribers
#We fill Kosovo with the median
mobileSubs_median = teamDataCleaned_df['MobileSubs'].median()
teamDataCleaned_df['MobileSubs'] = teamDataCleaned_df['MobileSubs'].fillna(mobileSubs_median)
#Description of the variable and World average
print(teamDataCleaned_df['MobileSubs'].describe())
print('\n')
print(worldData_df['MobileSubs'][worldData_df['CountryName']=='World'])
#X-bar plot
plt.title('Mobile Subcribers (per 100 people)')
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['MobileSubs'])
plt.xticks(ticks=teamDataCleaned_df.index, labels=teamDataCleaned_df['CountryName'],rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['MobileSubs'], bins='sturges')
plt.show()
#Seaborn plot
sns.distplot(teamDataCleaned_df['MobileSubs'], bins='sturges')
plt.title("Mobile Subcribers (per 100 people) - Seaborn")
plt.show()
#28. Poverty by Healthcare
#Description of the variable and World average
print(teamDataCleaned_df['PovertyByHealthcare'].describe())
print('\n')
print(worldData_df['PovertyByHealthcare'][worldData_df['CountryName']=='World'])
#X-bar plot
plt.title('Below Poverty Line < $3.10')
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['PovertyByHealthcare'])
plt.xticks(ticks=teamDataCleaned_df.index, labels=teamDataCleaned_df['CountryName'],rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['PovertyByHealthcare'], bins='sturges')
plt.show()
#Seaborn plot
sns.distplot(teamDataCleaned_df['PovertyByHealthcare'], bins='sturges')
plt.title("Below Poverty Line < $3.10 - Seaborn")
plt.show()
#29. Population Growth
#Description of the variable and World average
print(teamDataCleaned_df['PopulationGrowth'].describe())
print('\n')
print(worldData_df['PopulationGrowth'][worldData_df['CountryName']=='World'])
#X-bar plot
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['PopulationGrowth'])
plt.xticks(rotation=90)
plt.show()
#Histogram Plot
teamDataCleaned_df.hist(column=['PopulationGrowth'], bins='sturges')
plt.show()
#30. PopulationDensity
#Description of the variable and World average
print(teamDataCleaned_df['PopulationDensity'].describe())
print('\n')
print(worldData_df['PopulationDensity'][worldData_df['CountryName']=='World'])
#Bar chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['PopulationDensity'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['PopulationDensity'], bins='sturges')
plt.show()
#31. Population65+
#We complete Kosovo with the median
population65_median = round(teamDataCleaned_df['Population65+'].median())
teamDataCleaned_df['Population65+'] = teamDataCleaned_df['Population65+'].fillna(population65_median)
#Description of the variable and World average
print(teamDataCleaned_df['Population65+'].describe())
print('\n')
print(worldData_df['Population65+'][worldData_df['CountryName']=='World'])
#Bar Chart
plt.bar(x=teamDataCleaned_df.index, height=teamDataCleaned_df['Population65+'])
plt.xticks(rotation=90)
plt.show()
#Histogram
teamDataCleaned_df.hist(column=['Population65+'], bins='sturges')
plt.show()
#32. Population15_64
#We complete Kosovo with the median
population15_64_median = round(teamDataCleaned_df['Population15_64'].median())
teamDataCleaned_df['Population15_64'] = teamDataCleaned_df['Population15_64'].fillna(population15_64_median)