
์ฌ์ค ํ์๋ ์์ด๊ฐ ๋ ํธํ๋ค. ํ์์ ํ์ต์ ์ํด ์์ฑ ์ค์ธ ๋ธ๋ก๊ทธ์ธ ๋งํผ ํ๊ตญ๋ง์ด ์๊ฐ๋์ง ์์ผ๋ฉด ๊ทธ๋ฅ ์์ด๋ก ์ ๋๋ก ํ๊ฒ ๋ค. ๐ผ
apply()๋ฅผ ํ์ฉํ์ฌ df ํน์ Series์ ํจ์๋ฅผ ์ ์ฉ์ํฌ ์ ์๋ค.
"Dataframe C"

display(C)
G = C.copy() #Copy๋ฅผ ํ์ง ์์ผ๋ฉด the dataframe is modified
G['year] = G['year'].apply(lambda x: "'{:02d}".format(x % 100))
display(G)
"Dataframe G"

์๋ ๊ฒ ์ด๋ค ์ด๋ง์ด์ผ. ๊ทผ๋ฐ ์ด๊ฒ ์๋นํ ๋ณต์กํ๊ณ ์ ์ฉํด์ง๋ค.

์ฐ์ axis = 0๊ณผ axis = 1์ ๋ฐฉํฅ์ ์์ง ๋ง์.
G['prevalence'] = G['cases'] / G['popuation']
๋ฌผ๋ก ์๊ฐ ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ด์ง๋ง applyํจ์๋ฅผ ํ์ฉํ๋ ํจ์๋ฅผ ์์ฑํด๋ณด์.
def calc_prevalence(G):
assert 'cases' in G.columns and 'population' in G.columns
F = G.copy()
F['prevalence'] = F.apply(lambda row : row['cases']/row['population'], axis=1)
return F
display(calc_prevalence(G))
์์ธ์ง ํธ๋ฐ์ค ๋ฎ์ผ์ จ์ ๊ฑฐ ๊ฐ์์ค>< ์ ์ตํ ์ ๋ณด ๊ฐ์ฌํด์ฉ!!