#median3
Explore tagged Tumblr posts
deku1518 · 5 years ago
Text
Data Management and Visualization (Assignment-3) Making Data Management Decisions
Python Code:
""" Created on Tue Jun 23 20:10:16 2020
@author: KARTIKEYA """
import pandas import numpy
data= pandas.read_csv('gapminder.csv')
# Converting Variables name to lower-case data.columns= map(str.lower, data.columns)
# Used to avoid run-time errors pandas.set_option('display.float_format', lambda x:'%f'%x)
# Converting variables to be numeric data['co2emissions']= data['co2emissions'].apply(pandas.to_numeric, errors ='coerce') data['urbanrate']= data['urbanrate'].apply(pandas.to_numeric, errors ='coerce') data['relectricperperson']= data['relectricperperson'].apply(pandas.to_numeric, errors ='coerce')
# Mean of Urbanrate of countries print('The mean of Urbanrate of Countries') mean = data['urbanrate'].mean() print(mean)
# Countries with High  Urban Rate sub1= data[(data['urbanrate']>58) ]
# Making a copy of Subset sub2= sub1.copy()
#List of Countries with high urbanrate and their CO2 Emission and Electricity used per person print('Contries with High UrbanRate') sub9= sub2[['country','urbanrate','co2emissions','relectricperperson']] print(sub9.head(25))
# Countries with Low Urban Rate sub3= data[(data['urbanrate']<58) ]
# Making a copy of Subset sub4= sub3.copy()
#List of Countries with high urbanrate and their CO2 Emission and Electricity used per person print('Countries with Low UrbanRate') sub3= sub4[['country','urbanrate','co2emissions','relectricperperson']] print(sub3.head(25))
# Median of CO2 Emissions of countries with Low Urbanrate print('The median of CO2 Emission of Countries with Low Urbanrate') median1 = sub4['co2emissions'].median() print(median1)
# Median of CO2 Emissions of countries with High Urbanrate print('The median of CO2 Emission of Countries with High Urbanrate') median2 = sub2['co2emissions'].median() print(median2)
# Median of ElectricityperPerson of Countries with low Urbanrate print('The median of Electricity Used Per Person of Countries with Low Urbanrate') median3 = sub4['relectricperperson'].median() print(median3)
# Median of ElectricityperPerson of Countries with High Urbanrate print('The median of Electricity Used Per Person  with High Urbanrate') median4 = sub2['relectricperperson'].median() print(median4)
Output:
The mean of Urbanrate of Countries 56.76935960591131
Contries with High UrbanRate
          country  urbanrate       co2emissions  relectricperperson 2          Algeria  65.220000  2932108667.000000          590.509814 3          Andorra  88.920000                nan                 nan 6        Argentina  92.000000  5872119000.000000          768.428300 7          Armenia  63.860000    51219666.670000          603.763058 9        Australia  88.740000 12970092667.000000         2825.391095 10         Austria  67.160000  4466084333.000000         2068.123309 12         Bahamas  83.700000   137555000.000000                 nan 13         Bahrain  88.520000   503994333.300000         7314.355637 16         Belarus  73.460000   999874333.300000          614.907287 17         Belgium  97.360000 10897025333.000000         1920.962215 20         Bermuda 100.000000    20331666.670000                 nan 22         Bolivia  65.580000   254939666.700000          213.061614 24        Botswana  59.580000    78943333.330000          454.795705 25          Brazil  85.580000  9580226333.000000          498.165305 26          Brunei  74.820000   254206333.300000         3067.498901 27        Bulgaria  71.100000  3157700333.000000         1380.869289 32          Canada  80.400000 24979045667.000000         4772.370648 33      Cape Verde  59.620000     5214000.000000                 nan 34  Cayman Islands 100.000000     8968666.667000                 nan 37           Chile  88.440000  1839471333.000000          532.515177 39        Colombia  74.500000  2269806000.000000          404.591365 42     Congo, Rep.  61.340000    46306333.330000           56.372450 44      Costa Rica  63.260000   148470666.700000          798.340600 47            Cuba  75.660000  1286670000.000000          528.787350 48          Cyprus  69.900000   183535000.000000         2123.762863
Countries with Low UrbanRate                   country  urbanrate        co2emissions  relectricperperson 0              Afghanistan  24.040000     75944000.000000                 nan 1                  Albania  46.720000    223747333.300000          636.341383 4                   Angola  56.700000    248358000.000000          172.999227 5      Antigua and Barbuda  30.460000     16225000.000000                 nan 8                    Aruba  46.780000     35871000.000000                 nan 11              Azerbaijan  51.920000    511107666.700000          921.562111 14              Bangladesh  27.140000    598774000.000000           68.115229 15                Barbados  39.840000     36160666.670000                 nan 18                  Belize  51.700000     14058000.000000                 nan 19                   Benin  41.200000     37950000.000000           38.222943 21                  Bhutan  34.480000      6024333.333000                 nan 23  Bosnia and Herzegovina  47.440000    236419333.300000          927.119497 28            Burkina Faso  19.560000     20628666.670000                 nan 29                 Burundi  10.400000      8092333.333000                 nan 30                Cambodia  21.560000     45411666.670000           51.581320 31                Cameroon  56.760000    125172666.700000           59.551245 35    Central African Rep.  38.580000      8338000.000000                 nan 36                    Chad  26.680000      7608333.333000                 nan 38                   China  43.100000 101386000000.000000          331.376632 40                 Comoros  28.080000      2368666.667000                 nan 41        Congo, Dem. Rep.  33.960000    169180000.000000           30.709244 45           Cote d'Ivoire  48.780000    228748666.700000           70.387444 46                 Croatia  57.280000    310024000.000000         1494.410268 55                   Egypt  42.720000   3341129000.000000          536.760451 57       Equatorial Guinea  39.380000     26125000.000000                 nan
The median of CO2 Emission of Countries with Low Urbanrate 69329333.33
The median of CO2 Emission of Countries with High Urbanrate 1321661000.0
The median of Electricity Used Per Person of Countries with Low Urbanrate 187.3248822
The median of Electricity Used Per Person  with High Urbanrate 1142.309009
Summary:
1) Around 102 countries have high urban rate and 101 countries have low urban rate.
2) CO2 emission is more in countries with high urban rate as the median for it is  1321661000.0 which is more than  69329333.33 which is the median of CO2 Emission for countries with low urban rate.
3) Electricity used/person is more in countries with high urban rate as the median for it is   1142.309009 which is more than   187.3248822 which is the median of Electricity used/person for countries with low urban rate.
4) The list of countries that have high urbanrate mostly comprises of developed countries and the list of countries that have low urbanrate comprises of developing countries.
0 notes
pythonplay · 12 years ago
Text
An Elegant Way To Find Out Median Of Three Numbers In Python
There are multiple ways of doing this.
The first one is the comparison way -
>>> def median3(a,b,c): ... if a<b: ... if c<a: ... return a ... elif b<c: ... return b ... else: ... return c ... else: ... if a<c: ... return a ... elif c<b: ... return b ... else: ... return c ... >>> median3(1,5,2) 2 >>> median3(3,5,2) 3 >>> median3(3,5,7) 5 >>> median3(7,5,2) 5 >>> median3(7,5,1) 5 >>> median3(2,5,1) 2
this takes at least two comparisons and at most three to compute.
Another elegant way to do this might be to sort the three numbers and return the middle one.
Like this:
>>> def median3(a,b,c): ... return sorted([a,b,c])[1] ... >>> median3(1,5,2) 2 >>> median3(3,5,2) 3 >>> median3(3,5,7) 5 >>> median3(7,5,6) 6
0 notes
deku1518 · 5 years ago
Text
Data Management and Visualization (Assignment-2) Running Your First Program
Python Code:
""" Created on Thu Jun 18 16:14:28 2020
@author: KARTIKEYA """
import pandas import numpy
# Loading Data Set mydata = pandas.read_csv('gapminder.csv', low_memory= False)
# Converting Variables name to lower-case mydata.columns= map(str.lower, mydata.columns)
# Used to avoid run-time errors pandas.set_option('display.float_format', lambda x:'%f'%x)
# Converting variables to be numeric mydata['co2emissions']= mydata['co2emissions'].apply(pandas.to_numeric, errors ='coerce') mydata['urbanrate']= mydata['urbanrate'].apply(pandas.to_numeric, errors ='coerce') mydata['relectricperperson']= mydata['relectricperperson'].apply(pandas.to_numeric, errors ='coerce')
# Frequency count for CO2 Emissions print('Frequency Count of CO2 Emission') c1= mydata['co2emissions'].value_counts(sort = False) print(c1)
# Percentage for Co2 Emissions print('Percentage of CO2 Emission') p1= mydata['co2emissions'].value_counts(sort = False, normalize= True) print(p1)
# Frequency count for Urban Rate print('Frequency Count of Urban Rate') c2= mydata['urbanrate'].value_counts(sort = False) print(c2)
# Percentage for Urban Rate print('Percentage of Urban Rate') p2= mydata['urbanrate'].value_counts(sort = False, normalize= True) print(p2)
# Frequency count for Electricity Used Per Person print('Frequency Count of Electricity Used') c3= mydata['relectricperperson'].value_counts(sort = False) print(c3)
# Percentage for Electricity Used Per Person print('Percentage of Electricity Used') p3= mydata['relectricperperson'].value_counts(sort = False, normalize= True) print(p3)
# Countries with High  Urban Rate sub1= mydata[(mydata['urbanrate']>70) ]
# Making a copy of Subset sub2= sub1.copy()
# Sub Set Containing Countries whose Urbanrate > 70 c4= sub2['urbanrate'].value_counts(sort = False) print(c4)
# Sub Set Containing CO2 Emissions of countries with high Urbanrate c5= sub2['co2emissions'].value_counts(sort = False) print(c5)
# Countries with Low Urban Rate sub3= mydata[(mydata['urbanrate']<70) ]
# Making a copy of Subset sub4= sub3.copy()
# Sub Set Containing Countries whose Urbanrate < 70 c6= sub4['urbanrate'].value_counts(sort = False) print(c6)
# Sub Set Containing CO2 Emissions of countries with low Urbanrate c7= sub4['co2emissions'].value_counts(sort = False) print(c7)
# Median of CO2 Emissions of countries with Low Urbanrate print('The median of CO2 Emission of Countries with Low Urbanrate') median1 = sub4['co2emissions'].median() print(median1)
# Median of CO2 Emissions of countries with High Urbanrate print('The median of CO2 Emission of Countries with High Urbanrate') median2 = sub2['co2emissions'].median() print(median2)
# Sub Set Containing ElectricityperPerson of countries with high Urbanrate c8= sub2['relectricperperson'].value_counts(sort = False) print(c8)
# Sub Set Containing ElectricityperPerson of Countries with low Urbanrate c9= sub4['relectricperperson'].value_counts(sort = False) print(c9)
# Median of ElectricityperPerson of Countries with low Urbanrate print('The median of CO2 Emission of Countries with Low Urbanrate') median3 = sub4['relectricperperson'].median() print(median3)
# Median of ElectricityperPerson of Countries with High Urbanrate print('The median of CO2 Emission of Countries with High Urbanrate') median4 = sub2['relectricperperson'].median() print(median4)
Output:
Frequency Count of CO2 Emission: 5214000.000000       1 4286590000.000000    1 2329308667.000000    1 20331666.670000      1 1045000.000000       1                    .. 21332666.670000      1 2977333.333000       1 226255333.300000     1 322960000.000000     1 35717000.000000      1 Name: co2emissions, Length: 200, dtype: int64
Percentage of CO2 Emission: 5214000.000000      0.005000 4286590000.000000   0.005000 2329308667.000000   0.005000 20331666.670000     0.005000 1045000.000000      0.005000
21332666.670000     0.005000 2977333.333000      0.005000 226255333.300000    0.005000 322960000.000000    0.005000 35717000.000000     0.005000 Name: co2emissions, Length: 200, dtype: float64
Frequency Count of Urban Rate: 92.000000     1 100.000000    6 74.500000     1 73.500000     1 17.000000     1             .. 56.020000     1 57.180000     1 73.920000     1 25.460000     1 28.380000     1 Name: urbanrate, Length: 194, dtype: int64
Percentage of Urban Rate: 92.000000    0.004926 100.000000   0.029557 74.500000    0.004926 73.500000    0.004926 17.000000    0.004926
56.020000    0.004926 57.180000    0.004926 73.920000    0.004926 25.460000    0.004926 28.380000    0.004926 Name: urbanrate, Length: 194, dtype: float64
Frequency Count of Electricity Used: 0.000000       5 1585.174739    1 614.907287     1 904.669445     1 66.238522      1              .. 2826.044873    1 758.858719     1 532.515177     1 297.883200     1 38.222943      1 Name: relectricperperson, Length: 132, dtype: int64
Percentage of Electricity Used: 0.000000      0.036765 1585.174739   0.007353 614.907287    0.007353 904.669445    0.007353 66.238522     0.007353
2826.044873   0.007353 758.858719    0.007353 532.515177    0.007353 297.883200    0.007353 38.222943     0.007353 Name: relectricperperson, Length: 132, dtype: float64
Frequency Count UrbanRate >70: 92.000000     1 100.000000    6 74.500000     1 73.500000     1 77.540000     1 73.460000     1 70.360000     1 85.580000     1 88.920000     1 71.900000     1 77.880000     1 75.660000     1 72.840000     1 89.940000     1 83.520000     1 71.620000     1 94.260000     1 88.740000     1 86.680000     1 94.220000     1 81.820000     1 87.300000     1 83.700000     1 92.680000     1 92.300000     1 81.460000     1 82.440000     1 85.040000     1 73.480000     1 73.200000     1 80.460000     1 88.520000     1 98.320000     1 92.260000     1 88.440000     1 77.120000     1 86.560000     1 97.360000     1 73.640000     1 71.100000     1 71.400000     1 77.360000     1 93.160000     1 93.320000     1 77.200000     1 74.920000     1 77.480000     1 95.640000     1 73.920000     1 86.960000     1 81.700000     1 98.360000     1 78.420000     1 80.400000     1 74.820000     1 91.660000     1 84.540000     1 71.080000     1 82.420000     1 Name: urbanrate, dtype: int64
Frequency Count for CO2 Emission of Countries with UrbanRate>70: 4286590000.000000      1 1839471333.000000      1 1561079667.000000      1 20331666.670000        1 13304503667.000000     1 5872119000.000000      1 1723333.333000         1 10897025333.000000     1 3503877667.000000      1 1962704333.000000      1 14054333.330000        1 14241333.330000        1 487993000.000000       1 9580226333.000000      1 23404568000.000000     1 38397333.330000        1 275744333.300000       1 428006333.300000       1 33341634333.000000     1 334221000000.000000    1 102538333.300000       1 92770333.330000        1 2269806000.000000      1 1548044667.000000      1 377303666.700000       1 5418886000.000000      1 7861553333.000000      1 86317000.000000        1 254206333.300000       1 2670950333.000000      1 23635333.330000        1 24979045667.000000     1 73784333.330000        1 2406741333.000000      1 592012666.700000       1 9666891667.000000      1 10822529667.000000     1 170404666.700000       1 12970092667.000000     1 999874333.300000       1 1712755000.000000      1 1414031667.000000      1 1776016000.000000      1 1146277000.000000      1 1321661000.000000      1 72524250333.000000     1 1286670000.000000      1 811965000.000000       1 2401666.667000         1 3157700333.000000      1 2315698000.000000      1 137555000.000000       1 9483023000.000000      1 503994333.300000       1 170804333.300000       1 41229554667.000000     1 1206333.333000         1 1026813333.000000      1 8968666.667000         1 Name: co2emissions, dtype: int64
Frequency Count UrbanRate <70: 17.000000    1 61.000000    1 67.500000    1 25.460000    1 41.000000    1            .. 66.900000    1 26.460000    1 51.460000    1 17.960000    1 41.760000    1 Name: urbanrate, Length: 135, dtype: int64
Frequency Count for CO2 Emission of Countries with UrbanRate<70: 17515666.670000       1 49793333.330000       1 104170000.000000      1 5584766000.000000     1 19000454000.000000    1                     .. 226255333.300000      1 59473333.330000       1 322960000.000000      1 35717000.000000       1 214368000.000000      1 Name: co2emissions, Length: 133, dtype: int64
The median of CO2 Emission of Countries with Low Urbanrate: 125172666.7
The median of CO2 Emission of Countries with High Urbanrate: 1414031667.0
Electricity per Person in Countries with Urbanrate>70:
0.000000        1 4304.514402     1 614.907287      1 1464.837281     1 7432.130852     1 2361.033336     1 431.625379      1 846.014923      1 2124.608816     1 1920.962215     1 3433.932449     1 532.515177      1 1884.299342     1 1468.640784     1 1438.780412     1 8362.567977     1 1779.503510     1 825.941111      1 1933.945615     1 913.845660      1 2993.092660     1 3067.498901     1 4542.848695     1 767.970324      1 1490.056909     1 2342.435248     1 239.389457      1 1566.106139     1 2825.391095     1 2826.044873     1 823.823197      1 1380.869289     1 498.165305      1 7314.355637     1 768.428300      1 4759.453844     1 1142.309009     1 1693.891898     1 537.104738      1 2539.753273     1 969.004339      1 1598.673959     1 528.787350      1 500.288505      1 4772.370648     1 404.591365      1 719.476530      1 11154.755030    1 Name: relectricperperson, dtype: int64
Electricity per Person in Countries with Urbanrate<70
17515666.670000       1 49793333.330000       1 104170000.000000      1 5584766000.000000     1 19000454000.000000    1                     .. 226255333.300000      1 59473333.330000       1 322960000.000000      1 35717000.000000       1 214368000.000000      1 Name: co2emissions, Length: 133, dtype: int64
The median of CO2 Emission of Countries with Low Urbanrate 320.33288025
The median of CO2 Emission of Countries with High Urbanrate 1528.081524
Summary:
1) As the median of CO2 Emission in countries with low urbanrate is lesser than that of countries with high urbanrate. So, it can be concluded that CO2 Emission is high in countries whose urbanrate is high.
2) As the median of Electricity/person in countries with low urbanrate is lesser than that of countries with high urbanrate. So, it can be concluded that Electricity/person is high in countries whose urbanrate is high.
Thus High Urban Rate without sustainability is deteriorating the environment.
0 notes