file I/O


In [ ]:
# ./ -> 현재 폴더
# ../ -> 상위폴더

In [14]:
f = open("./animals.txt", "r") #mode -> w,r, wr

In [6]:
# read, readline, readlines

In [9]:
f.read() #파일의 전체 데이터


Out[9]:
'bird\nbjs\nsih'

In [13]:
f.readline()


Out[13]:
'bird\n'

In [15]:
f.readlines()


Out[15]:
['bird\n', 'bjs\n', 'sih']

In [16]:
f = open("./animals.txt", "w")

In [17]:
f.write("hellow world")

In [18]:
f.close()

In [19]:
with open("./anmials.txt", "w") as f:
    f.write("hellow world")
#f.close()가 담겨있음

In [21]:
with open("./stars.txt", "w")as f:
    for i in range(5):
        f.write("*" * (i+1))

function


In [ ]:
# 작업의 자동화

In [35]:
def print_star(count):
    """
    this function makes star
    """
    for i in range(count):
        print("*" * (i+1))

In [29]:
print_star(3)


*
**
***

In [36]:
print_star(int(input("count?")))


count?5
*
**
***
****
*****

In [37]:
print_star?  # 위에 주석으로 함수의 description 을 할 수 있다.

Distribution


In [6]:
import scipy.stats
import scipy as sp
mu = 0
std = 1
rv = sp.stats.norm(mu, std)


Out[6]:
<scipy.stats._distn_infrastructure.rv_frozen at 0x4048e70>

In [11]:
import numpy as np
import matplotlib.pyplot as plt
xx = np.linspace(-5, 5, 100)
plt.plot(xx, rv.pdf(xx))
plt.show()



In [13]:
# normality test // qq plot
np.random.seed(0)
x = np.random.randn(100)
plt.figure(figsize=(7,7))
sp.stats.probplot(x, plot=plt)
plt.show()



In [ ]:


In [ ]:


In [ ]: