Test - kamchur/note GitHub Wiki

  • ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์ปฌ๋Ÿผ strํƒ€์ž…๋ณ€๊ฒฝ
# ํ•œ ์ปฌ๋Ÿผ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์Šฌ๋ผ์ด์‹ฑํ•˜์—ฌ ์ƒˆ๋กœ์šด ์ปฌ๋Ÿผ์„ ๋งŒ๋“ค์–ด๋‚ด๋ ค ํ•˜๋Š”๋ฐ
# ๋‘ ๋ฒˆ์งธ ๊ฐ’๊นŒ์ง€ ์Šฌ๋ผ์ด์‹ฑํ•˜๋ ค ํ–ˆ๋Š”๋ฐ, 'intํƒ€์ž…`์€ ์Šฌ๋ผ์ด์‹ฑ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค.
# ๊ฐ’์„ ์ „๋‹ฌํ•  ์›๋ณธ ์ปฌ๋Ÿผ์€ `object`ํ˜•์ด๋‹ค
data['new_column'] = data['old_column'].astype('str')
data['new_column'] = data['new_column'].str.slice(start=0, stop=2)

  • ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ intํ˜•์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฐ์ดํ„ฐ์•ˆ์— NaN์ด ์žˆ์œผ๋ฉด floatํ˜•์œผ๋กœ ํ‘œ์ถœ๋œ๋‹ค๊ณ  ์ฃผ์›Œ๋“ค์—ˆ๋‹ค. ์ง„์ง ๊ฐ€?
test = {'a':[1,2,3,4,5,np.nan,6,7,8,9], 'b':[1,2,3,4,5,6,7,8,9,10]}
test = pd.DataFrame(test)

>>> display(test['a'].dtype)
dtype('float64')

>>> display(test['b'].dtype)
dtype('int64')

  • ๋ฆฌ์ŠคํŠธ ๊ฐœ์ˆ˜๋ณด๋‹ค ํฐ ๊ฐœ์ˆ˜ ์Šฌ๋ผ์ด์‹ฑ ํ•œ ๊ฒฝ์šฐ
# web crawling์‹œ payload์—์„œ item_ids๋ฅผ ๊ฐ€์ ธ์™€์•ผ ํ•˜๋Š”๋ฐ
# 1000๊ฐœ์ด์ƒ์˜ ๋ฐ์ดํ„ฐ๋Š” 990~1000๊ฐœ๊นŒ์ง€ item_ids ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์–ด์„œ
# 900๊ฐœ์”ฉ ๋Š์–ด์„œ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์—ˆ๋‹ค

>>> list1 = list('abcdefg')
>>> list1[:90]
['a', 'b', 'c', 'd', 'e', 'f', 'g']

# ์Šฌ๋ผ์ด์‹ฑ ๊ฐ’์ด ์ปค๋„ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๊ฒƒ์— ํฐ ๋ฌธ์ œ๋Š” ์—†์—ˆ๋‹ค
  • ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
>>> list = [[] * 5]
>>> list
[[]]

>>> list = [] * 5
>>> list
[]

>>> list = [[0] * 5]
>>> list
[[0, 0, 0, 0, 0]]

>>> list1 = [[0]] * 5
>>> list1
[[0], [0], [0], [0], [0]]
โš ๏ธ **GitHub.com Fallback** โš ๏ธ