Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

데이터분석 공부하기

[판다스] 함수(list comprehension, lambda, map, apply, applymap) 본문

Python

[판다스] 함수(list comprehension, lambda, map, apply, applymap)

Eileen's 2021. 10. 19. 15:30
  • list comprehension : [출력표현식 for  요소 in  입력 Sequence [if 조건식]] 
    -Python의 네가지 comprehension 기능 중 하나 (list, set, dict, generator)
    -반복 가능한 iterable 자료형을 생성할 때 사용, 여러 줄의 for/if 조건문도 한 줄로 만들 수 있다
    -입력 Sequence로부터 지정된 표현식에 따라 새로운 리스트 컬렉션을 만듬
    -문법 : 
  • lambda(lambda arguments : expression) : '한 줄'로 함수를 표현하는 익명 함수 기법
 f = lambda x, y : x+y
 f(3,4)​
  • map(function, sequence) : input(func, seq)을 each element에 적용하여 list로 리턴
x = [1, 2, 3, 4]
f = lambda x : x * 2
list(map(f, x))​
  • apply() : acts as a map() function, it takes function as an input & apply it to an entire dateframe
  • applymap() : element-wise on a dataframe only

 

 

Iterator vs Iterable vs Generator

-출처: https://mingrammer.com/translation-iterators-vs-generators/

-참고 블로그 : https://ooyoung.tistory.com/96