[dataquest/python] Data Scientist in Python

joseon0thing·2023년 8월 21일
0

python

목록 보기
14/17
post-thumbnail

기본 내용이기 때문에 함수만 정리함.

+) 번역기 돌리지 말고 (영어를) 해석해 이해해보자!

round( )

If we want to round a number to the nearest whole number, we can use the round() function

One thing to remember is that using the round() function doestn't acutally change the value stored in a variable.
To do that, we need to store the rounded value back into the variavle.

Positive, Negative indexing

Positive indexing
: the first element has the index number 0, the second element has the index number 1, and so on.

Negative indexing
: the last element has the index number -1, the second to last element has the index number -2, and so on.

IndexError

Notice that if we use an index number that is outside the range of the two indexing systems

Output
IndexError: list index out of range

for Loops

내 생각과 다르게 나온 예제

row_1 = ['Facebook', 0.0, 'USD', 2974676, 3.5]
row_2 = ['Instagram', 0.0, 'USD', 2161558, 4.5]
row_3 = ['Clash of Clans', 0.0, 'USD', 2130805, 4.5]
row_4 = ['Fruit Ninja Classic', 1.99, 'USD', 698516, 4.5]
row_5 = ['Minecraft: Pocket Edition', 6.99, 'USD', 522012, 4.5]

app_data_set = [row_1, row_2, row_3, row_4, row_5]

for row in app_data_set:
    rating_count = row[3]
    print(rating_count)

for - in 이므로 원소를 하나하나 받아

rating_count = row[3]

이 코드에서 에러가 날 거라고 생각함. (리스트 자체가 생성이 불가능하다고 생각)

정상 출력이 되어 for문에

print(row)

코드를 추가해 봄

row_1 (리스트) 자체를 넘기는 것을 확인할 수 있음.

row_1에 들어가 하나하나 꺼내오는 것이 아닌 row_1 자체를 넘기는 것을 알게 됨.

dataset - open( )

opened_file = open('AppleStore.csv')

returned the output <_io.TextIOWrapper name='AppleStore.csv' mode='r' encoding='UTF-8'>.
The output is an object.

dataset - reader( )

from csv import reader
read_file = reader(opened_file)

csv module using

dataset - list( )

we've read the file, we can transform it into a list

apps_data = list(read_file)

sum( )

괄호 안에 변수 넣으면 자동 계산

profile
정리.velog

0개의 댓글