-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfonksiyonlara_docstring_ozellik_ekleme.py
82 lines (67 loc) · 3.04 KB
/
fonksiyonlara_docstring_ozellik_ekleme.py
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
###############################################
# Fonksiyonlara Özellik Ekleme VE Docstring Ekleme
###############################################
###############################################
# GÖREV 1: Fonksiyonlara Özellik Ekleme
###############################################
# cat_summary() fonksiyonuna 1 özellik ekleyiniz. Bu özellik argumanla biçimlendirilebilir olsun.
# Var olan özelliği de argumandan kontrol edilebilir hale getirebilirsiniz.
# ÖNCESİ
def check_df(dataframe, head=5):
print("##################### Shape #####################")
print(dataframe.shape)
print("##################### Types #####################")
print(dataframe.dtypes)
print("##################### Head #####################")
print(dataframe.head(head))
print("##################### Tail #####################")
print(dataframe.tail(head))
print("##################### NA #####################")
print(dataframe.isnull().sum())
print("##################### Quantiles #####################")
print(dataframe.quantile([0, 0.05, 0.50, 0.95, 0.99, 1]).T)
# SONRASI
def check_df(dataframe, head=5, tail=5, quan=False):
print("##################### Shape #####################")
print(dataframe.shape)
print("##################### Types #####################")
print(dataframe.dtypes)
print("##################### Head #####################")
print(dataframe.head(head))
print("##################### Tail #####################")
print(dataframe.tail(tail))
print("##################### NA #####################")
print(dataframe.isnull().sum())
if quan:
print("##################### Quantiles #####################")
print(dataframe.quantile([0, 0.05, 0.50, 0.95, 0.99, 1]).T)
import pandas as pd
df = pd.read_csv("datasets/titanic.csv")
check_df(df, head=3, tail=3, quan=True)
###############################################
# cat_summary() için ratio özelliği argumana verilmiştir.
###############################################
import seaborn as sns
import matplotlib.pyplot as plt
# ÖNCESİ
def cat_summary(dataframe, col_name, plot=False):
print(pd.DataFrame({col_name: dataframe[col_name].value_counts(),
"Ratio": 100 * dataframe[col_name].value_counts() / len(dataframe)}))
print("##########################################")
if plot:
sns.countplot(x=dataframe[col_name], data=dataframe)
plt.show()
cat_summary(df, "Sex")
# SONRASI
def cat_summary(dataframe, col_name, plot=False, ratio=True):
if ratio:
print(pd.DataFrame({col_name: dataframe[col_name].value_counts(),
"Ratio": 100 * dataframe[col_name].value_counts() / len(dataframe)}))
print("##########################################")
else:
print(pd.DataFrame({col_name: dataframe[col_name].value_counts()}))
print("##########################################")
if plot:
sns.countplot(x=dataframe[col_name], data=dataframe)
plt.show()
cat_summary(df, "Sex", plot=False, ratio=False)