In [1]:
"My name is %s" % "Tom"


Out[1]:
'My name is Tom'

In [2]:
"{1}'s score is {0}, {0}, {0}, {0}, {0}, {0}, {0}".format(100, "Jane")


Out[2]:
"Jane's score is 100, 100, 100, 100, 100, 100, 100"

In [4]:
a = 100

if a %2 == 0:
    print('짝수')
else:
    print('홀수')


짝수

In [8]:
sex = "boy"
pushup = 5

if sex == "boy":
    if pushup >=10:
        grade = "Pass"
    else:
        grade = "Fail"

        
print(grade)


Fail

In [9]:
def twotimes(x):
    y = 2 * x
    return y

In [10]:
twotimes(2)


Out[10]:
4

In [12]:
for i in range(4):
    print("*")


*
*
*
*

In [15]:
for i in range(6):
    n1 = i + 1
    for j in range(6):
        n2 = j + 1
        print(n1, n2)


(1, 1)
(1, 2)
(1, 3)
(1, 4)
(1, 5)
(1, 6)
(2, 1)
(2, 2)
(2, 3)
(2, 4)
(2, 5)
(2, 6)
(3, 1)
(3, 2)
(3, 3)
(3, 4)
(3, 5)
(3, 6)
(4, 1)
(4, 2)
(4, 3)
(4, 4)
(4, 5)
(4, 6)
(5, 1)
(5, 2)
(5, 3)
(5, 4)
(5, 5)
(5, 6)
(6, 1)
(6, 2)
(6, 3)
(6, 4)
(6, 5)
(6, 6)

In [22]:
tips = sns.load_dataset('tips')

In [21]:
import seaborn as sns

In [23]:
tips.tail()


Out[23]:
total_bill tip sex smoker day time size
239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2

In [24]:
tips['tip_pct'] = tips['tip'] / tips['total_bill']

In [25]:
tips.tail()


Out[25]:
total_bill tip sex smoker day time size tip_pct
239 29.03 5.92 Male No Sat Dinner 3 0.203927
240 27.18 2.00 Female Yes Sat Dinner 2 0.073584
241 22.67 2.00 Male Yes Sat Dinner 2 0.088222
242 17.82 1.75 Male No Sat Dinner 2 0.098204
243 18.78 3.00 Female No Thur Dinner 2 0.159744

In [26]:
tips.describe()


Out[26]:
total_bill tip size tip_pct
count 244.000000 244.000000 244.000000 244.000000
mean 19.785943 2.998279 2.569672 0.160803
std 8.902412 1.383638 0.951100 0.061072
min 3.070000 1.000000 1.000000 0.035638
25% 13.347500 2.000000 2.000000 0.129127
50% 17.795000 2.900000 2.000000 0.154770
75% 24.127500 3.562500 3.000000 0.191475
max 50.810000 10.000000 6.000000 0.710345

In [27]:
tips.groupby('sex').count()


Out[27]:
total_bill tip smoker day time size tip_pct
sex
Male 157 157 157 157 157 157 157
Female 87 87 87 87 87 87 87

In [28]:
tips.groupby(['sex', 'smoker']).size()


Out[28]:
sex     smoker
Male    Yes       60
        No        97
Female  Yes       33
        No        54
dtype: int64

In [31]:
tips.pivot_table("tip_pct", "sex", "smoker", aggfunc="count", margins=True)


Out[31]:
smoker Yes No All
sex
Male 60.0 97.0 157.0
Female 33.0 54.0 87.0
All 93.0 151.0 244.0

In [32]:
tips.groupby(["sex", "smoker"])[["tip", "tip_pct"]].describe()


Out[32]:
tip tip_pct
sex smoker
Male Yes count 60.000000 60.000000
mean 3.051167 0.152771
std 1.500120 0.090588
min 1.000000 0.035638
25% 2.000000 0.101845
50% 3.000000 0.141015
75% 3.820000 0.191697
max 10.000000 0.710345
No count 97.000000 97.000000
mean 3.113402 0.160669
std 1.489559 0.041849
min 1.250000 0.071804
25% 2.000000 0.131810
50% 2.740000 0.157604
75% 3.710000 0.186220
max 9.000000 0.291990
Female Yes count 33.000000 33.000000
mean 2.931515 0.182150
std 1.219916 0.071595
min 1.000000 0.056433
25% 2.000000 0.152439
50% 2.880000 0.173913
75% 3.500000 0.198216
max 6.500000 0.416667
No count 54.000000 54.000000
mean 2.773519 0.156921
std 1.128425 0.036421
min 1.000000 0.056797
25% 2.000000 0.139708
50% 2.680000 0.149691
75% 3.437500 0.181630
max 5.200000 0.252672

In [36]:
def peak_to_peak(x):
    return x.max() - x.min()

tips.groupby(['sex', 'smoker'])[['tip']].agg(peak_to_peak)


Out[36]:
tip
sex smoker
Male Yes 9.00
No 7.75
Female Yes 5.50
No 4.20

In [37]:
tips.groupby('sex').count()


Out[37]:
total_bill tip smoker day time size tip_pct
sex
Male 157 157 157 157 157 157 157
Female 87 87 87 87 87 87 87

In [ ]:


In [ ]: