728x90

데이터 엔지니어링에 대해 공부할 때, 사전에 필요한 지식 중 하나인 파이썬에 대해서도 Udacity에서 정리를 해두어서 복습차 쭉 정리해서 듣고 있다. 물론 기본적인 개념이고 현재 내가 메인으로 쓰고 있는 언어도 파이썬이라 듣지않아도 되겠다 생각했지만,

가장 기본적인 개념이 제일 중요한 만큼 한번 쭉 정리하다가 내가 새로 이해하게 된 부분은 추가적으로 정리해보려 한다.

 

While "True" is a valid boolean expression, it's not useful as a condition since it always evaluates to True, so the indented code will always get run. Similarly, if False is not a condition you should use either - the statement following this if statement would never be executed.

 

Recall that the dictionary get method is another way to retrieve the value of a key in a dictionary. Except unlike indexing, this will return a default value if the key is not found. If unspecified, this default value is set to None. We can use get with a default value of 0 to simplify the code from the first method above.

book_title =  ['great', 'expectations','the', 'adventures', 'of', 'sherlock','holmes','the','great','gasby','hamlet','adventures','of','huckleberry','fin']
word_counter = {}
for word in book_title:
    word_counter[word] = word_counter.get(word, 0) + 1

word_counter = {'great': 2, 'expectations': 1, 'the': 2, 'adventures': 2, 'of': 2, 'sherlock': 1, 'holmes': 1, 'gasby': 1, 'hamlet': 1, 'huckleberry': 1, 'fin': 1}

for loops are ideal when the number of iterations is known or finite

while loops are ideal when the iterations need to continue until a condition is met.

 

ZIP

letters = ['a', 'b', 'c']
nums = [1, 2, 3]

for letter, num in zip(letters, nums):
    print("{}: {}".format(letter, num))

some_list = [('a', 1), ('b', 2), ('c', 3)]
letters, nums = zip(*some_list)

 

Enumerate

letters = ['a', 'b', 'c', 'd', 'e']
for i, letter in enumerate(letters):
    print(i, letter)

0 a
1 b
2 c
3 d
4 e
squares = [x**2 for x in range(9) if x % 2 == 0]
squares = [x**2 if x % 2 == 0 else x + 3 for x in range(9)]

Lambda Expressions

You can use lambda expressions to create anonymous functions. That is, functions that don’t have a name.

multiply = lambda x, y: x * y

가장 유용한 라이브러리

1. NumPy

 

Overview — NumPy v1.22.dev0 Manual

 

numpy.org

2. Pandas

 

pandas documentation — pandas 1.3.1 documentation

The reference guide contains a detailed description of the pandas API. The reference describes how the methods work and which parameters can be used. It assumes that you have an understanding of the key concepts.

pandas.pydata.org

 

728x90

+ Recent posts