1.Python Basics

variable

In [1]:
var1 = 10 # integer = int
ay = "temmuz"
var3 = 10.3 # double (float)

s = "bugun gunlerden pazartesi"
variable_type = type(s)   # str = string
print(variable_type)
<class 'str'>

user defined functions

In [2]:
def benim_ilk_func(a,b):   
    """
    bu benim ilk denemem
    parametre: 
    return: 
    """
    output = (((a+b)*50)/100.0)*a/b
    return output

print(benim_ilk_func(20,50))
14.0

default ve flexible functions

In [3]:
# %% 
# default f: cemberin cevre uzunlugu = 2*pi*r
def cember_cevresi_hesapla(r,pi=3.14):
    """
    cember cevresi hesapla
    input(parametre): r,pi
    output = cemberin cevresi
    """
    output = 2*pi*r
    return output

# flexible
def hesapla(boy,kilo,*args):
    print(args)
    output = (boy+kilo)*args[0]
    return output

print(cember_cevresi_hesapla(5))
print(hesapla(5,5,10,20,30,40))
31.400000000000002
(10, 20, 30, 40)
100

lambda function

In [4]:
def hesapla(x):
    return x*x
print(hesapla(3))

sonuc2 = lambda x: x*x
print(sonuc2(3))
9
9

nested function

In [5]:
def square():
    """ return square of value """
    def add():
        """ add two local variable """
        x = 2
        y = 3
        z = x + y
        return z
    return add()**2
print(square())
25

anonymous function

In [6]:
number_list = [1,2,3]
y = map(lambda x:x**2,number_list)
print(list(y))
[1, 4, 9]

list

In [7]:
liste = [1,2,3,4,5,6]
print(type(liste))

liste_str = ["ptesi","sali","cars"]
print(type(liste_str))

print(liste[1])
print(liste[-1])
print(liste[0:3])

liste.append(7)
print(liste)
liste.remove(7)
print(liste)
liste.reverse()
print(liste)

liste2 = [1,5,4,3,6,7,2]
liste2.sort()
print(liste2)

string_int_liste = [1,2,3,"aa","bb"]
<class 'list'>
<class 'list'>
2
6
[1, 2, 3]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6]
[6, 5, 4, 3, 2, 1]
[1, 2, 3, 4, 5, 6, 7]

tuple

In [8]:
t = (1,2,3,3,4,5,6)

print(t.count(5))
print(t.index(3))
1
2

dictionary

In [9]:
def deneme():
    dictionary = {"ali":32,"veli":45,"ayse":13}
    # ali ,veli ,ayse = keys
# 32,45,13 = values
    return dictionary

dic = deneme()
print(dic)

dictionary = {'spain' : 'madrid','usa' : 'vegas'}
print(dictionary.keys())
print(dictionary.values())
dictionary['spain'] = "barcelona"    # update existing entry
print(dictionary)
dictionary['france'] = "paris"       # Add new entry
print(dictionary)
del dictionary['spain']              # remove entry with key 'spain'
print(dictionary)
print('france' in dictionary)        # check include or not
dictionary.clear()                   # remove all entries in dict
print(dictionary)
{'ali': 32, 'veli': 45, 'ayse': 13}
dict_keys(['spain', 'usa'])
dict_values(['madrid', 'vegas'])
{'spain': 'barcelona', 'usa': 'vegas'}
{'spain': 'barcelona', 'usa': 'vegas', 'france': 'paris'}
{'usa': 'vegas', 'france': 'paris'}
True
{}

conditionals

In [10]:
# if else statement

var1 = 10
var2 = 20

if(var1 > var2):
    print("var1 buyuktur var2")
elif(var1 == var2):
    print("var and var2 esitler")
else:
    print("var1 kucuktur var2")


liste = [1,2,3,4,5]

value = 3
if value in liste:
    print("evet {} degeri listenin icinde".format(value))
else:
    print("hayir")

dictionary = {"ali":32,"veli":45,"ayse":13}
keys = dictionary.keys()

if "veli" in keys:
    print("evet")
else:
    print("hayir")
var1 kucuktur var2
evet 3 degeri listenin icinde
evet

loops

In [11]:
# for loop
for each in range(1,3):
    print(each)
    
for each in "ank ist":
    print(each)
    
for each in "ank ist".split(): 
    print(each)
    
liste = [1,4,5,6,8,3,3,4,67]
 
print(sum(liste))  

count = 0
for each in liste:
    count = count + each
    print(count)

# while loop
i = 0
while(i <4):
    print(i)
    i = i + 1
1
2
a
n
k
 
i
s
t
ank
ist
101
1
5
10
16
24
27
30
34
101
0
1
2
3

2.Object Oriented Programming

class

In [12]:
class Calisan:
    zam_orani = 1.8
    counter = 0
    def __init__(self,isim,soyisim,maas): # constructor
        self.isim = isim
        self.soyisim = soyisim
        self.maas = maas
        self.email = isim+soyisim+"@asd.com"
        Calisan.counter = Calisan.counter + 1
    
    def giveNameSurname(self):
        return self.isim +" " +self.soyisim
        
    def zam_yap(self):
        self.maas = self.maas + self.maas*self.zam_orani
# class variable
calisan1 = Calisan("ali", "veli",100) 
print("giveNameSurname: ",calisan1.giveNameSurname())
print("maas: ",calisan1.maas)
calisan1.zam_yap()
print("yeni maas: ",calisan1.maas)

#  class example
calisan2 = Calisan("ayse", "hatice",200) 
calisan3 = Calisan("ayse", "yelda",600) 
liste  = [calisan1,calisan2,calisan3]

maxi_maas = -1
index = -1
for each in liste:
    if(each.maas>maxi_maas):
        maxi_maas = each.maas
        index = each
        
print(maxi_maas)
print(index.giveNameSurname())
giveNameSurname:  ali veli
maas:  100
yeni maas:  280.0
600
ayse yelda

3.Numpy

In [13]:
# importing
import numpy as np
# numpy basics
array = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])  # 1*15 vector
print(array.shape)
a = array.reshape(-1,1)
print("shape: ",a.shape)
print("dimension: ", a.ndim)
print("data type: ",a.dtype.name)
print("size: ",a.size)
print("type: ",type(a))

array1 = np.array([[1,2,3,4],[5,6,7,8],[9,8,7,5]])
print(array1)
zeros = np.zeros((3,4))
zeros[0,0] = 5
print(zeros)

print(np.ones((3,4)))
print(np.empty((2,3)))

a = np.arange(10,50,5) # 10 dan 50 ye 5er 5 er artır
print(a)
a = np.linspace(10,50,5) #10 50 ye 5 tane yerleştir
print(a)
(15,)
shape:  (15, 1)
dimension:  2
data type:  int64
size:  15
type:  <class 'numpy.ndarray'>
[[1 2 3 4]
 [5 6 7 8]
 [9 8 7 5]]
[[5. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]
[[1. 1. 1. 1.]
 [1. 1. 1. 1.]
 [1. 1. 1. 1.]]
[[6.90775820e-310 4.68763801e-310 0.00000000e+000]
 [0.00000000e+000 0.00000000e+000 0.00000000e+000]]
[10 15 20 25 30 35 40 45]
[10. 20. 30. 40. 50.]

basic operations

In [14]:
a = np.array([1,2,3])
b = np.array([4,5,6])

print(a+b)
print(a-b)
print(a**2)

a = np.array([[1,2,3],[4,5,6]])
b = np.array([[1,2,3],[4,5,6]])
# element wise prodcut
print(a*b)
# matrix prodcut
print(a.dot(b.T))

a = np.random.random((2,2)) # 2 2 lık 0-1 arasında sayı uretiyor
print(a.sum())
print(a.max())
print(a.min())
print(a.sum(axis=0)) # sutunları topla
print(a.sum(axis=1)) # satırları topla
print(np.sqrt(a))
print(np.square(a)) # a**2
print(np.add(a,a))
[5 7 9]
[-3 -3 -3]
[1 4 9]
[[ 1  4  9]
 [16 25 36]]
[[14 32]
 [32 77]]
1.6048975803280638
0.6462414920820414
0.17529048584698315
[0.35945829 1.24543929]
[0.77448829 0.83040929]
[[0.41867707 0.77407868]
 [0.42914776 0.80389147]]
[[0.03072675 0.359038  ]
 [0.03391778 0.41762807]]
[[0.35058097 1.1983956 ]
 [0.36833561 1.29248298]]

indexing and slicing

In [15]:
import numpy as np
array = np.array([1,2,3,4,5,6,7])   #  vector dimension = 1
print(array[0])
print(array[0:4])

reverse_array = array[::-1]
print(reverse_array)

array1 = np.array([[1,2,3,4,5],[6,7,8,9,10]])
print(array1[1,1]) # 1 satır 1 sutun 7 
print(array1[:,1]) # tum satır 1 sutun 2,7 
print(array1[1,1:4]) # 1 satır 1-4 sutun 7-8-9
print(array1[-1,:]) #son satırın tum sutunları
print(array1[:,-1]) # tum satırların son sutunu 5,10
1
[1 2 3 4]
[7 6 5 4 3 2 1]
7
[2 7]
[7 8 9]
[ 6  7  8  9 10]
[ 5 10]

shape manipulation

In [16]:
array = np.array([[1,2,3],[4,5,6],[7,8,9]])

# flatten
array1 = array.ravel() # duz hale getırıldı
print(array1)
array2 = array1.reshape(3,3) # matrıse cevır
print(array2)

# %% stacking arrays
array1 = np.array([[1,2],[3,4]])
array2 = np.array([[-1,-2],[-3,-4]])

# veritical
#array([[1, 2],
#       [3, 4]])
#array([[-1, -2],
#       [-3, -4]])
array3 = np.vstack((array1,array2))
print(array3)
# horizontal
#array([[1, 2],[-1, -2],
#       [3, 4]],[-3, -4]]
array4 = np.hstack((array1,array2))
print(array4)
[1 2 3 4 5 6 7 8 9]
[[1 2 3]
 [4 5 6]
 [7 8 9]]
[[ 1  2]
 [ 3  4]
 [-1 -2]
 [-3 -4]]
[[ 1  2 -1 -2]
 [ 3  4 -3 -4]]

convert and copy

In [17]:
liste = [1,2,3,4]   # list
array = np.array(liste) #np.array
liste2 = list(array) # list

a = np.array([1,2,3])
b = a
b[0] = 5
print(b[0])
print(a[0]) # a da degıstı

d =  np.array([1,2,3])
e = d.copy()
d[0] = 5
print(d[0])
print(e[0]) # e da degısmedi
5
5
5
1

4.Pandas

In [18]:
import pandas as pd

dictionary = {"NAME":["ali","veli","kenan","hilal","ayse","evren","isim1","isim2","isim3"],
              "AGE":[15,16,17,33,45,66,70,70,70],
              "MAAS": [100,150,240,350,110,220,300,300,300]} 

dataFrame1 = pd.DataFrame(dictionary)

print(dataFrame1.head()) # ilk 5 kısım, içerindeki görmek için
print(dataFrame1.tail()) # sondaki 5 tane
    NAME  AGE  MAAS
0    ali   15   100
1   veli   16   150
2  kenan   17   240
3  hilal   33   350
4   ayse   45   110
    NAME  AGE  MAAS
4   ayse   45   110
5  evren   66   220
6  isim1   70   300
7  isim2   70   300
8  isim3   70   300
In [19]:
# pandas basic method
print(dataFrame1.columns)
print("------")
print(dataFrame1.info())
print("------")
print(dataFrame1.dtypes)
print("------")
print(dataFrame1.describe())  # numeric feature = columns (age,maas)
Index(['NAME', 'AGE', 'MAAS'], dtype='object')
------
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 9 entries, 0 to 8
Data columns (total 3 columns):
NAME    9 non-null object
AGE     9 non-null int64
MAAS    9 non-null int64
dtypes: int64(2), object(1)
memory usage: 296.0+ bytes
None
------
NAME    object
AGE      int64
MAAS     int64
dtype: object
------
             AGE        MAAS
count   9.000000    9.000000
mean   44.666667  230.000000
std    24.959968   91.515026
min    15.000000  100.000000
25%    17.000000  150.000000
50%    45.000000  240.000000
75%    70.000000  300.000000
max    70.000000  350.000000

indexing and slicing

In [20]:
print(dataFrame1["AGE"])
print(dataFrame1.AGE)

dictionary = {"NAME":["ali","veli","kenan",],
              "AGE":[15,16,17,],
              "MAAS": [100,150,240]} 

dataFrame1 = pd.DataFrame(dictionary)
dataFrame1["yeni_feature"] = [-1,-2,-3]
print("---1---")
print(dataFrame1.loc[:, "AGE"])
print("---2---")
print(dataFrame1.loc[:1, "AGE"])
print("---3---")
print(dataFrame1.loc[:1, "AGE":"NAME"])
print("---4---")
print(dataFrame1.loc[:1, ["AGE","NAME"]])
print("---5---")
print(dataFrame1.loc[::-1,:]) #ters yazdı
print("---6---")
print(dataFrame1.loc[:,:"NAME"])
print("---7---")
print(dataFrame1.loc[:,"NAME"])
print("---8---")
print(dataFrame1.iloc[:,2]) #i integer location name yerıne sutun ındexı verdık
0    15
1    16
2    17
3    33
4    45
5    66
6    70
7    70
8    70
Name: AGE, dtype: int64
0    15
1    16
2    17
3    33
4    45
5    66
6    70
7    70
8    70
Name: AGE, dtype: int64
---1---
0    15
1    16
2    17
Name: AGE, dtype: int64
---2---
0    15
1    16
Name: AGE, dtype: int64
---3---
Empty DataFrame
Columns: []
Index: [0, 1]
---4---
   AGE  NAME
0   15   ali
1   16  veli
---5---
    NAME  AGE  MAAS  yeni_feature
2  kenan   17   240            -3
1   veli   16   150            -2
0    ali   15   100            -1
---6---
    NAME
0    ali
1   veli
2  kenan
---7---
0      ali
1     veli
2    kenan
Name: NAME, dtype: object
---8---
0    100
1    150
2    240
Name: MAAS, dtype: int64

filtering

In [21]:
dictionary = {"NAME":["ali","veli","kenan","hilal","ayse","evren"],
              "AGE":[15,16,17,33,45,66],
              "MAAS": [100,150,240,350,110,220]} 
dataFrame1 = pd.DataFrame(dictionary)
filtre1 = dataFrame1.MAAS > 200
print(filtre1)
filtrelenmis_data = dataFrame1[filtre1]
print(filtrelenmis_data)
filtre2 = dataFrame1.AGE <20
dataFrame1[filtre1 & filtre2]
print(dataFrame1[dataFrame1.AGE > 60])
0    False
1    False
2     True
3     True
4    False
5     True
Name: MAAS, dtype: bool
    NAME  AGE  MAAS
2  kenan   17   240
3  hilal   33   350
5  evren   66   220
    NAME  AGE  MAAS
5  evren   66   220

list comprehension

In [22]:
import numpy as np
dataFrame1 = pd.DataFrame(dictionary)
ortalama_maas = dataFrame1.MAAS.mean()
# ortalama_maas_np = np.mean(dataFrame1.MAAS)
dataFrame1["maas_seviyesi"] = ["dusuk" if ortalama_maas > each else "yuksek" for each in dataFrame1.MAAS]
print(dataFrame1)
print(dataFrame1.columns)
dataFrame1.columns = [ each.lower() for each in dataFrame1.columns] 
print(dataFrame1.columns)
dataFrame1.columns = [each.split()[0]+"_"+each.split()[1] if(len(each.split())>1) else each for each in dataFrame1.columns]
print(dataFrame1) # bosluklu sutun adı varsa _ ekledı ama bızım verıler zaten bosluksuz
    NAME  AGE  MAAS maas_seviyesi
0    ali   15   100         dusuk
1   veli   16   150         dusuk
2  kenan   17   240        yuksek
3  hilal   33   350        yuksek
4   ayse   45   110         dusuk
5  evren   66   220        yuksek
Index(['NAME', 'AGE', 'MAAS', 'maas_seviyesi'], dtype='object')
Index(['name', 'age', 'maas', 'maas_seviyesi'], dtype='object')
    name  age  maas maas_seviyesi
0    ali   15   100         dusuk
1   veli   16   150         dusuk
2  kenan   17   240        yuksek
3  hilal   33   350        yuksek
4   ayse   45   110         dusuk
5  evren   66   220        yuksek

drop and concatenating

In [23]:
dataFrame1["yeni_feature"] = [-1,-2,-3,-4,-5,-6]
dataFrame1.drop(["yeni_feature"],axis=1,inplace = True)
# dataFrame1 = dataFrame1.drop(["yeni_feature"],axis=1)
data1 = dataFrame1.head()
print(data1)
data2 = dataFrame1.tail()
print(data2)
# vertical
data_concat = pd.concat([data1,data2],axis=0) #dusey bırlestırdı yanı ust uste
print(data_concat)
# horizontal
maas = dataFrame1.maas
age = dataFrame1.age
data_h_concat = pd.concat([maas,age],axis=1) #yatay bırlestırdı yanı yanyana
print(data_h_concat)
    name  age  maas maas_seviyesi
0    ali   15   100         dusuk
1   veli   16   150         dusuk
2  kenan   17   240        yuksek
3  hilal   33   350        yuksek
4   ayse   45   110         dusuk
    name  age  maas maas_seviyesi
1   veli   16   150         dusuk
2  kenan   17   240        yuksek
3  hilal   33   350        yuksek
4   ayse   45   110         dusuk
5  evren   66   220        yuksek
    name  age  maas maas_seviyesi
0    ali   15   100         dusuk
1   veli   16   150         dusuk
2  kenan   17   240        yuksek
3  hilal   33   350        yuksek
4   ayse   45   110         dusuk
1   veli   16   150         dusuk
2  kenan   17   240        yuksek
3  hilal   33   350        yuksek
4   ayse   45   110         dusuk
5  evren   66   220        yuksek
   maas  age
0   100   15
1   150   16
2   240   17
3   350   33
4   110   45
5   220   66

transforming data

In [24]:
def multiply(age):
    return age*2
dataFrame1["apply_metodu"] = dataFrame1.age.apply(multiply)
dataFrame1["list_comp"] = [ each*2 for each in dataFrame1.age]
print(dataFrame1)
    name  age  maas maas_seviyesi  apply_metodu  list_comp
0    ali   15   100         dusuk            30         30
1   veli   16   150         dusuk            32         32
2  kenan   17   240        yuksek            34         34
3  hilal   33   350        yuksek            66         66
4   ayse   45   110         dusuk            90         90
5  evren   66   220        yuksek           132        132

iteration example

In [25]:
name = "ronaldo"
it = iter(name)
print(next(it))    # print next iteration
print(*it)         # print remaining iteration
r
o n a l d o

zip example

In [26]:
list1 = [1,2,3,4]
list2 = [5,6,7,8]
z = zip(list1,list2)
print(z)
z_list = list(z)
print(z_list)
print("-----")
un_zip = zip(*z_list)
un_list1,un_list2 = list(un_zip) # unzip returns tuble
print(un_list1)
print(un_list2)
print(type(un_list2))
<zip object at 0x7f28e50d5188>
[(1, 5), (2, 6), (3, 7), (4, 8)]
-----
(1, 2, 3, 4)
(5, 6, 7, 8)
<class 'tuple'>

example of list comprehension

In [27]:
num1 = [1,2,3]
num2 = [i + 1 for i in num1 ]
print(num2)
# Conditionals on iterable
num1 = [5,10,15]
num2 = [i**2 if i == 10 else i-5 if i < 7 else i+5 for i in num1]
print(num2)
[2, 3, 4]
[0, 100, 20]

5.Visualization with Matplotlib

In [28]:
import pandas as pd
data = pd.read_csv("../input/Iris.csv")
print(data.columns)
Index(['Id', 'SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm',
       'Species'],
      dtype='object')
In [29]:
print(data.Species.unique())
['Iris-setosa' 'Iris-versicolor' 'Iris-virginica']
In [30]:
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150 entries, 0 to 149
Data columns (total 6 columns):
Id               150 non-null int64
SepalLengthCm    150 non-null float64
SepalWidthCm     150 non-null float64
PetalLengthCm    150 non-null float64
PetalWidthCm     150 non-null float64
Species          150 non-null object
dtypes: float64(4), int64(1), object(1)
memory usage: 7.1+ KB
In [31]:
data.describe()
Out[31]:
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm
count 150.000000 150.000000 150.000000 150.000000 150.000000
mean 75.500000 5.843333 3.054000 3.758667 1.198667
std 43.445368 0.828066 0.433594 1.764420 0.763161
min 1.000000 4.300000 2.000000 1.000000 0.100000
25% 38.250000 5.100000 2.800000 1.600000 0.300000
50% 75.500000 5.800000 3.000000 4.350000 1.300000
75% 112.750000 6.400000 3.300000 5.100000 1.800000
max 150.000000 7.900000 4.400000 6.900000 2.500000
In [32]:
df1 = data.drop(["Id"],axis=1)
df1.corr()
Out[32]:
SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm
SepalLengthCm 1.000000 -0.109369 0.871754 0.817954
SepalWidthCm -0.109369 1.000000 -0.420516 -0.356544
PetalLengthCm 0.871754 -0.420516 1.000000 0.962757
PetalWidthCm 0.817954 -0.356544 0.962757 1.000000
In [33]:
setosa = data[data.Species == "Iris-setosa"]
versicolor = data[data.Species == "Iris-versicolor"]
print(setosa.describe())
print(versicolor.describe())
             Id  SepalLengthCm      ...       PetalLengthCm  PetalWidthCm
count  50.00000       50.00000      ...           50.000000      50.00000
mean   25.50000        5.00600      ...            1.464000       0.24400
std    14.57738        0.35249      ...            0.173511       0.10721
min     1.00000        4.30000      ...            1.000000       0.10000
25%    13.25000        4.80000      ...            1.400000       0.20000
50%    25.50000        5.00000      ...            1.500000       0.20000
75%    37.75000        5.20000      ...            1.575000       0.30000
max    50.00000        5.80000      ...            1.900000       0.60000

[8 rows x 5 columns]
              Id  SepalLengthCm      ...       PetalLengthCm  PetalWidthCm
count   50.00000      50.000000      ...           50.000000     50.000000
mean    75.50000       5.936000      ...            4.260000      1.326000
std     14.57738       0.516171      ...            0.469911      0.197753
min     51.00000       4.900000      ...            3.000000      1.000000
25%     63.25000       5.600000      ...            4.000000      1.200000
50%     75.50000       5.900000      ...            4.350000      1.300000
75%     87.75000       6.300000      ...            4.600000      1.500000
max    100.00000       7.000000      ...            5.100000      1.800000

[8 rows x 5 columns]
In [34]:
import matplotlib.pyplot as plt

setosa = data[data.Species == "Iris-setosa"]
versicolor = data[data.Species == "Iris-versicolor"]
virginica = data[data.Species == "Iris-virginica"]

plt.plot(setosa.Id,setosa.PetalLengthCm,color="red",label= "setosa")
plt.plot(versicolor.Id,versicolor.PetalLengthCm,color="green",label= "versicolor")
plt.plot(virginica.Id,virginica.PetalLengthCm,color="blue",label= "virginica")
plt.legend()
plt.xlabel("Id")
plt.ylabel("PetalLengthCm")
plt.show()

# clf() = cleans it up again you can start a fresh
#plt.clf()

line Plot example

In [35]:
# color = color, label = label, linewidth = width of line, alpha = opacity, grid = grid, linestyle = sytle of line
data.SepalLengthCm.plot(kind = 'line', color = 'g',label = 'SepalLengthCm',linewidth=1,alpha = 0.5,grid = True,linestyle = ':')
data.PetalLengthCm.plot(color = 'r',label = 'PetalLengthCm',linewidth=1, alpha = 0.5,grid = True,linestyle = '-.')
plt.legend(loc='upper right')     # legend = puts label into plot
plt.xlabel('x axis')              # label = name of label
plt.ylabel('y axis')
plt.title('Line Plot')            # title = title of plot
plt.show()

scatter plot

In [36]:
setosa = data[data.Species == "Iris-setosa"]
versicolor = data[data.Species == "Iris-versicolor"]
virginica = data[data.Species == "Iris-virginica"]

plt.scatter(setosa.PetalLengthCm,setosa.PetalWidthCm,color="red",label="setosa")
plt.scatter(versicolor.PetalLengthCm,versicolor.PetalWidthCm,color="green",label="versicolor")
plt.scatter(virginica.PetalLengthCm,virginica.PetalWidthCm,color="blue",label="virginica")
plt.legend()
plt.xlabel("PetalLengthCm")
plt.ylabel("PetalWidthCm")
plt.title("scatter plot")
plt.show()

histogram

In [37]:
plt.hist(setosa.PetalLengthCm,bins= 10)
plt.xlabel("PetalLengthCm values")
plt.ylabel("frekans")
plt.title("hist")
plt.show()

bar plot

In [38]:
import numpy as np

x = np.array([1,2,3,4,5,6,7])
a = ["turkey","usa","a","b","v","d","s"]
y = x*2+5

plt.bar(a,y)
plt.title("bar plot")
plt.xlabel("x")
plt.ylabel("y")
plt.show()

subplots

In [39]:
df1 = data.drop(["Id"],axis=1)
df1.plot(grid=True,alpha= 0.9,subplots = True)
plt.show()

setosa = data[data.Species == "Iris-setosa"]
versicolor = data[data.Species == "Iris-versicolor"]
virginica = data[data.Species == "Iris-virginica"]

plt.subplot(2,1,1)
plt.plot(setosa.Id,setosa.PetalLengthCm,color="red",label= "setosa")
plt.ylabel("setosa -PetalLengthCm")
plt.subplot(2,1,2)
plt.plot(versicolor.Id,versicolor.PetalLengthCm,color="green",label= "versicolor")
plt.ylabel("versicolor -PetalLengthCm")
plt.show()