Python Library - kamchur/note GitHub Wiki

knowlege


- Pyhton ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

Pandas : ๋ฐ์ดํ„ฐ ํ•ธ๋“ค๋ง๊ณผ ๋ถ„์„์— ์œ ์šฉํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
Numpy : ๋‹ค์ฐจ์› ๋ฐฐ์—ด ๋ฐ ์ˆ˜ํ•™์  ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
Seaborn : ํ†ต๊ณ„๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
Matplotlib : ์ผ๋ฐ˜์ ์ธ ํŒŒ์ด์ฌ ์‹œ๊ฐํ™”๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
Scipy : ์ˆ˜ํ•™, ๊ณผํ•™๋ถ„์•ผ์—์„œ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๊ณ„์‚ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

docstring ''' ~ ''' ์‚ฌ์šฉ๋ฐฉ๋ฒ•

def function(arg1, arg2):
    '''This function returns to sum arg1 and arg2
    Params
    ------
    arg1 : int : first argument(ํŒŒ๋ผ๋ฉ”ํ„ฐ ์„ค๋ช… ๊ฐ„๋‹จํ•˜๊ฒŒ)
    arg2 : int : second argument

    Return
    ------
    type : str
    '''

    a = arg1
    b = arg1

    return sum(a, b)

normal

๊ณ ์ •์†Œ์ˆ˜์  ๋ณ€ํ™˜

data1, data2 = 0.1, 0.2
(data1 + data2) == 0.3     # False, 0.3000000000004

# 1. ๋ฐ˜์˜ฌ๋ฆผ : ์†๋„๊ฐ€ ๋น ๋ฅด์ง€๋งŒ ์†Œ์ˆ˜์  ์œ„์น˜ ์ง€์ •์œผ๋กœ์ธํ•ด ๋ถˆํŽธ
roun(data, ์†Œ์ˆ˜์ ์œ„์น˜)

# 2. ๊ณ ์ •์†Œ์ˆ˜์  : ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ธฐ ๋•Œ๋ฌธ์— ์†๋„๊ฐ€ ๋Šฆ์Œ
from decimal import Decimal
# 2์ง„์ˆ˜๋กœ ์—ฐ์‚ฐํ•˜๋Š”๊ฒƒ์ด ์•„๋‹Œ 10์ง„์ˆ˜๋กœ ๊ณ„์‚ฐ์„ ํ•จ
Decimal(str(data1)) + Decimal(str(data2))

๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์ฃผ๋Š” ํ•จ์ˆ˜

'str_variable'.upper()

apply()

๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ํ•จ์ˆ˜์— ๋Œ€์ž…ํ•œ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
data_frame.apply(lambda data:float(data.replace(',', '')))
`data_frame`์˜ ๋ฐ์ดํ„ฐ์˜ `,`์„ ๊ณต๋ฐฑ์ฒ˜๋ฆฌํ•˜์—ฌ ์ ์šฉ์‹œํ‚ด

copy()

๋ฐ์ดํ„ฐ์— ๊ฐ’์„ ๋„ฃ์œผ๋ฉด ๋ฐ์ดํ„ฐ๋Š” ํ•ด๋‹น ๊ฐ’์— ๋Œ€ํ•œ `์ฃผ์†Œ`๋ฅผ ๊ฐ€์ง
call by reference : ์–•์€ ๋ณต์‚ฌ 
์ฃผ์†Œ๊ฐ’๋งŒ ๋ณต์‚ฌํ•˜๊ฒŒ๋˜์–ด ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ”๊พธ์–ด๋„ ์ฃผ์†Œ๊ฐ€ ๊ฐ™์€ ๋ณ€์ˆ˜๋“ค๋„ ๋ฐ”๋€ ๋ฐ์ดํ„ฐ๊ฐ€ ํ‘œ์ถœ๋จ

call by value : ๊นŠ์€ ๋ณต์‚ฌ
์ฃผ์†Œ๋ฅผ ์ƒˆ๋กœ๋งŒ๋“ค์–ด ๋„ฃ์œผ๋ ค๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์ƒˆ๋กœ ๋งŒ๋“  ์ฃผ์†Œ๋ฅผ ์ฐธ์กฐํ•จ

data1 = [1, 2, 3]
data2 = data1
print(data1, data2)   #[1, 2, 3], [1, 2, 3]
data1[1] = 4
print(data1, data2)   #[1, 4, 3], [1, 2, 3]

lambda

โš ๏ธ **GitHub.com Fallback** โš ๏ธ