# Rozdział 2.1

``````import pandas as pd

``````##      Marka Model     Cena  KM  Pojemnosc  Przebieg   Paliwo  Produkcja
## 0  Peugeot   206   8799.0  60       1100   85000.0  benzyna       2003
## 1  Peugeot   206  15500.0  60       1124  114000.0  benzyna       2005
## 2  Peugeot   206  11900.0  90       1997  215000.0   diesel       2003
## 3  Peugeot   206  10999.0  70       1868  165000.0   diesel       2003
## 4  Peugeot   206  11900.0  70       1398  146000.0   diesel       2005``````

# Rozdział 2.2.1

``````from scipy import *

print(array([2, 3, 5, 7, 11, 13, 17]))``````
``## [ 2  3  5  7 11 13 17]``
``````from scipy import *

print(arange(-3, 3+1, 1))``````
``## [-3 -2 -1  0  1  2  3]``
``````from scipy import *

print(arange(0, 100+1, 11))``````
``## [ 0 11 22 33 44 55 66 77 88 99]``
``````import datetime

sol = [ datetime.date(2017, i + 1, 1).strftime('%B') for i in range(12) ]
print(sol)``````
``## ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']``
``````import string

LETTERS = list(string.ascii_uppercase)
print(LETTERS)``````
``## ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']``

# Rozdział 2.2.1.1*

``````import string

LETTERS = list(string.ascii_uppercase)
print(LETTERS[5-1:10])``````
``## ['E', 'F', 'G', 'H', 'I', 'J']``
``````import string

LETTERS = list(string.ascii_uppercase)
sol = [ LETTERS[i] for i in [0,1,8,9,10,11,12,13]]
print(sol)``````
``## ['A', 'B', 'I', 'J', 'K', 'L', 'M', 'N']``
``````import string

LETTERS = list(string.ascii_uppercase)
print(LETTERS[0:len(LETTERS):2])``````
``## ['A', 'C', 'E', 'G', 'I', 'K', 'M', 'O', 'Q', 'S', 'U', 'W', 'Y']``
``````import datetime

sol = [ datetime.date(2017, i + 1, 1).strftime('%B') for i in range(12) ]
del sol[4:9]
print(sol)``````
``## ['January', 'February', 'March', 'April', 'October', 'November', 'December']``
``````from scipy import *

wartosc = array([(1, 'pion'), (3, 'skoczek'),(3, 'goniec'),(5, 'wieza'),(9, 'hetman'),(float('inf'), 'krol')])

print(wartosc[::-1],'\n')

print(wartosc[2])``````
``````## [['inf' 'krol']
##  ['9' 'hetman']
##  ['5' 'wieza']
##  ['3' 'goniec']
##  ['3' 'skoczek']
##  ['1' 'pion']]
##
## ['3' 'goniec']``````

# Rozdział 2.2.2

``````import warnings
warnings.filterwarnings("ignore")

import pandas.rpy.common as com
``````##    gatunek   waga  dlugosc  predkosc  habitat  zywotnosc druzyna
## 1   Tygrys  300.0      2.5        60     Azja         25     Kot
## 2      Lew  200.0      2.0        80   Afryka         29     Kot
## 3   Jaguar  100.0      1.7        90  Ameryka         15     Kot
## 4     Puma   80.0      1.7        70  Ameryka         13     Kot
## 5  Leopard   70.0      1.4        85     Azja         21     Kot``````

# Rozdział 2.2.2.1

``````import warnings
warnings.filterwarnings("ignore")

import pandas as pd
import pandas.rpy.common as com

print(koty_ptaki.ix[[1,3,5],[1,2,3,4]],'\n')

print(koty_ptaki.loc[koty_ptaki["predkosc"] > 100, ["gatunek","predkosc","dlugosc"]])``````
``````##    gatunek   waga  dlugosc  predkosc  habitat  zywotnosc druzyna
## 1   Tygrys  300.0      2.5        60     Azja         25     Kot
## 3   Jaguar  100.0      1.7        90  Ameryka         15     Kot
## 5  Leopard   70.0      1.4        85     Azja         21     Kot
##
##     waga  dlugosc  predkosc  habitat
## 1  300.0      2.5        60     Azja
## 3  100.0      1.7        90  Ameryka
## 5   70.0      1.4        85     Azja
##
##            gatunek  predkosc  dlugosc
## 6           Gepard       115      1.4
## 8           Jerzyk       170      0.2
## 10   Orzel przedni       160      0.9
## 11  Sokol wedrowny       110      0.5
## 13        Albatros       120      0.8``````
``````import warnings
warnings.filterwarnings("ignore")

import pandas as pd
import pandas.rpy.common as com

print(koty_ptaki["predkosc"],'\n')

koty_ptaki['predkosc_mile'] = koty_ptaki["predkosc"] * 1.6
``````## 1      60
## 2      80
## 3      90
## 4      70
## 5      85
## 6     115
## 7      65
## 8     170
## 9      70
## 10    160
## 11    110
## 12    100
## 13    120
## Name: predkosc, dtype: int32
##
##   gatunek   waga  dlugosc  predkosc habitat  zywotnosc druzyna  predkosc_mile
## 1  Tygrys  300.0      2.5        60    Azja         25     Kot           96.0
## 2     Lew  200.0      2.0        80  Afryka         29     Kot          128.0``````

# Rozdział 2.2.3

``````import string

LETTERS = list(string.ascii_uppercase)
trojka = {'liczby':[1,2,3,4,5],'litery':LETTERS,'logika':[True,True,True,False]}
print(trojka,'\n')

print(trojka['logika'])``````
``````## {'liczby': [1, 2, 3, 4, 5], 'logika': [True, True, True, False], 'litery': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']}
##
## [True, True, True, False]``````

# Rozdział 2.3

``````import warnings
warnings.filterwarnings("ignore")

import pandas as pd
import pandas.rpy.common as com

``````##    wiek wyksztalcenie st.cywilny       plec              praca  \
## 1    70      zawodowe  w zwiazku  mezczyzna  uczen lub pracuje
## 2    66      zawodowe  w zwiazku    kobieta  uczen lub pracuje
## 3    71      zawodowe    singiel    kobieta  uczen lub pracuje
## 4    57       srednie  w zwiazku  mezczyzna  uczen lub pracuje
##
##    cisnienie.skurczowe  cisnienie.rozkurczowe
## 1                  143                     83
## 2                  123                     80
## 3                  167                     80
## 4                  150                     87``````

# Rozdział 2.3.1

``````import warnings
warnings.filterwarnings("ignore")

from scipy import *
import pandas as pd
import pandas.rpy.common as com

print(daneSoc['wiek'].min(),daneSoc['wiek'].max())``````
``## 22 75``
``````import warnings
warnings.filterwarnings("ignore")

from scipy import stats
import pandas as pd
import pandas.rpy.common as com

print(stats.trim_mean(daneSoc['wiek'], 0.2))``````
``## 42.5806451613``
``````import warnings
warnings.filterwarnings("ignore")

from scipy import *
import pandas as pd
import pandas.rpy.common as com

print(daneSoc['wiek'].median())``````
``## 45.0``
``````import warnings
warnings.filterwarnings("ignore")

import pandas as pd
import pandas.rpy.common as com

print(daneSoc['wiek'].describe())``````
``````## count    204.000000
## mean      43.161765
## std       13.847100
## min       22.000000
## 25%       30.000000
## 50%       45.000000
## 75%       53.000000
## max       75.000000
## Name: wiek, dtype: float64``````
``````import warnings
warnings.filterwarnings("ignore")

from scipy import *
import pandas as pd
import pandas.rpy.common as com

print(std(daneSoc['wiek'], ddof=1))``````
``## 13.8470999195``
``````import warnings
warnings.filterwarnings("ignore")

from scipy import stats
import pandas as pd
import pandas.rpy.common as com

print(stats.kurtosis(daneSoc['wiek']))``````
``## -0.935658875845816``
``````import warnings
warnings.filterwarnings("ignore")

from scipy import stats
import pandas as pd
import pandas.rpy.common as com

print(stats.skew(daneSoc['wiek']))``````
``## 0.23487589610214818``
``````import warnings
warnings.filterwarnings("ignore")

from scipy import *
import pandas as pd
import pandas.rpy.common as com

print(percentile(daneSoc['wiek'],[10,25,50,75,90]))``````
``## [ 26.   30.   45.   53.   62.4]``
``````import warnings
warnings.filterwarnings("ignore")

from scipy import *
import pandas as pd
import pandas.rpy.common as com

print(daneSoc.iloc[:,[0,5,6]].apply(lambda x: (x-mean(x))/std(x,ddof=1)).cov())``````
``````##                            wiek  cisnienie.skurczowe  cisnienie.rozkurczowe
## wiek                   1.000000            -0.027652              -0.083137
## cisnienie.skurczowe   -0.027652             1.000000               0.678527
## cisnienie.rozkurczowe -0.083137             0.678527               1.000000``````

# Rozdział 2.3.2

``````import warnings
warnings.filterwarnings("ignore")

from scipy import *
import pandas as pd
import pandas.rpy.common as com

print(daneSoc['wyksztalcenie'].value_counts())``````
``````## podstawowe    93
## srednie       55
## wyzsze        34
## zawodowe      22
## Name: wyksztalcenie, dtype: int64``````
``````import warnings
warnings.filterwarnings("ignore")

from scipy import *
import pandas as pd
import pandas.rpy.common as com

print(pd.crosstab(daneSoc['wyksztalcenie'],daneSoc['praca']))``````
``````## praca          nie pracuje  uczen lub pracuje
## wyksztalcenie
## podstawowe              22                 71
## srednie                 16                 39
## wyzsze                   6                 28
## zawodowe                 8                 14``````
``````import warnings
warnings.filterwarnings("ignore")

import pandas as pd
import pandas.rpy.common as com

print(daneSoc.iloc[:,[0,1,2,3]].describe(include='all'))``````
``````##               wiek wyksztalcenie st.cywilny       plec
## count   204.000000           204        204        204
## unique         NaN             4          2          2
## top            NaN    podstawowe    singiel  mezczyzna
## freq           NaN            93        120        149
## mean     43.161765           NaN        NaN        NaN
## std      13.847100           NaN        NaN        NaN
## min      22.000000           NaN        NaN        NaN
## 25%      30.000000           NaN        NaN        NaN
## 50%      45.000000           NaN        NaN        NaN
## 75%      53.000000           NaN        NaN        NaN
## max      75.000000           NaN        NaN        NaN``````

# Rozdział 2.4.1

``````import warnings
warnings.filterwarnings("ignore")

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

fig = plt.figure(figsize=(14,6))
sns.countplot(y="wyksztalcenie",color='C0', data=daneSoc,ax=ax1,order=daneSoc.wyksztalcenie.value_counts().iloc[:4].index)
sns.countplot(x="wyksztalcenie", hue="plec", data=daneSoc,ax=ax2,order=daneSoc.wyksztalcenie.value_counts().iloc[:4].index)
fig.tight_layout()
fig.savefig('rys_2.1.png')``````