In [7]:
from IPython.display import HTML
# Youtube
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/9xoqXVjBEF8" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>')
Out[7]:
In [1]:
import pandas as pd
In [6]:
df = pd.read_csv('train.csv')
df.head()
Out[6]:
PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked
0 1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/5 21171 7.2500 NaN S
1 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 0 PC 17599 71.2833 C85 C
2 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.9250 NaN S
3 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1000 C123 S
4 5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.0500 NaN S
In [8]:
df.Survived.value_counts()
Out[8]:
0    549
1    342
Name: Survived, dtype: int64
In [15]:
# sag kalanlarin orani
df.Survived.value_counts()[1]/ len(df.Survived)
Out[15]:
0.38383838383838381
In [16]:
df.Sex.value_counts()
Out[16]:
male      577
female    314
Name: Sex, dtype: int64
In [21]:
import matplotlib.pyplot as plt
df.Sex.value_counts().plot(kind = 'bar')
plt.show()
In [23]:
df.Pclass.value_counts()
Out[23]:
3    491
1    216
2    184
Name: Pclass, dtype: int64
In [24]:
df.Pclass.value_counts().plot(kind = 'bar')
plt.show()
In [35]:
df[df.Pclass == 1].Survived.value_counts().plot(kind = 'bar', color = 'g')
plt.title("1. sinif yolculari, sag kalanlar ve kalamayanlar")
plt.grid()
plt.show()
In [34]:
df[df.Pclass == 2].Survived.value_counts().plot(kind = 'bar')
plt.title("2. sinif yolculari, sag kalamayanlar ve kalanlar")
plt.grid()
plt.show()
In [36]:
df[df.Pclass == 3].Survived.value_counts().plot(kind = 'bar', color = 'r')
plt.title("3. sinif yolculari, sag kalamayanlar ve kalanlar")
plt.grid()
plt.show()
In [49]:
# once cocuklar ve kadinlar?
plt.subplot(1, 3, 1)
df[df.Sex == 'female'].Survived.value_counts().plot(kind = 'barh', color = 'r')
plt.title("Kadinlar")

plt.subplot(1, 3, 2)
df[df.Sex == 'male'].Survived.value_counts().plot(kind = 'barh', color = 'k')
plt.title("Erkekler")

plt.subplot(1, 3, 3)
df[df.Age < 15].Survived.value_counts().plot(kind = 'barh', color = 'b')
plt.title("Cocuklar")
plt.show()
In [53]:
# once cocuklar ve kadinlar?
df[(df.Age < 15) & (df.Sex == 'female')].Survived.value_counts().plot(kind = 'barh', color = 'b')
plt.title("once cocuklar ve kadinlar?")
plt.grid()
plt.show()
In [57]:
# once zenginler ve kadinlar?
df[(df.Pclass == 1) & (df.Sex == 'female')].Survived.value_counts().plot(kind = 'barh', color = 'g')
plt.title("once zenginler ve kadinlar?")
plt.grid()
plt.show()
In [58]:
# en son fakirler ve erkekler?
df[(df.Pclass == 3) & (df.Sex == 'male')].Survived.value_counts().plot(kind = 'barh', color = 'r')
plt.title("en son fakirler ve erkekler?")
plt.grid()
plt.show()

Star Wars Film Inclemesi

Bunun icin Ilker Birbil hocanin veri defterindeki yazisini okumanizi tavsiye ederim. Oradan ufak bir kod parcasini paylasmadan gecemeyecegim. Guc sizinle olsun :)

In [2]:
from requests import get
# swapi, the Star Wars API! 
adres = 'http://swapi.co/api'
In [3]:
# Yıldız Savaşları Filmleri
ys_filmler = get(adres+'/films/').json()

sonuclar = ys_filmler['results']
kayan_yazi = sonuclar[1]['opening_crawl']
kayan_yazi
Out[3]:
'There is unrest in the Galactic\r\nSenate. Several thousand solar\r\nsystems have declared their\r\nintentions to leave the Republic.\r\n\r\nThis separatist movement,\r\nunder the leadership of the\r\nmysterious Count Dooku, has\r\nmade it difficult for the limited\r\nnumber of Jedi Knights to maintain \r\npeace and order in the galaxy.\r\n\r\nSenator Amidala, the former\r\nQueen of Naboo, is returning\r\nto the Galactic Senate to vote\r\non the critical issue of creating\r\nan ARMY OF THE REPUBLIC\r\nto assist the overwhelmed\r\nJedi....'
In [4]:
from time import sleep
for yazi in kayan_yazi.split("\n"):
    print(yazi)
    sleep(0.5) # Yarim saniye bekletelim
There is unrest in the Galactic
Senate. Several thousand solar
systems have declared their
intentions to leave the Republic.

This separatist movement,
under the leadership of the
mysterious Count Dooku, has
made it difficult for the limited
number of Jedi Knights to maintain 
peace and order in the galaxy.

Senator Amidala, the former
Queen of Naboo, is returning
to the Galactic Senate to vote
on the critical issue of creating
an ARMY OF THE REPUBLIC
to assist the overwhelmed
Jedi....
In [ ]: