codestates / codestates/ds-blog
[최근후] Python 101 (DS Bootcamp 2일차)
- Dominant language
- No language data
- Stars
- 2
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
# Python
### Python은 매우 단순한 언어고, 매우 직설적인 구문을 가지고 있다.
.
- Python에서 가장 간단한 지시어는 **"print()"** 지시어인데, 그것은 단순히 선을 인쇄한다
```py
print("출력할 내용")
```
```py
출력할 내용
```
.
- 파이썬을 사용할 때는 중괄호 대신 **들여쓰기**를 사용한다.
```py
x = 5
if x < 7:
print("x는 7보다 작다") # 들여쓰기
else:
print("x는 7보다 크거나 같다") # 들여쓰기
```
.
- Pandas 는 데이터 조작 도구다. 이것의 데이터 구조인 DataFrame 을 사용하면 행과 변수 열에 표 형식의 데이터를 저장하고 조작할 수 있다.
```py
dict = {"country": ["Brazil", "Russia", "India", "China", "South Africa"],
"capital": ["Brasilia", "Moscow", "New Dehli", "Beijing", "Pretoria"],
"area": [8.516, 17.10, 3.286, 9.597, 1.221],
"population": [200.4, 143.5, 1252, 1357, 52.98] }
import pandas as pd
brics = pd.DataFrame(dict)
print(brics)
```
```py
country capital area population
0 Brazil Brasilia 8.516 200.40
1 Russia Moscow 17.100 143.50
2 India New Dehli 3.286 1252.00
3 China Beijing 9.597 1357.00
4 South Africa Pretoria 1.221 52.98
```
우리는 iloc[], loc[], head(), sample(), tail(), shape, columns 같은 함수들을 이용해 데이터프레임에서 우리가 원하는 값을 볼 수 있다.
.
- Numpy array는 Python Lists의 훌륭한 대안이다. Numpy array 의 주요 장점 중 일부는 사용자가 전체 어레이에 걸쳐 계산을 수행할 수 있게한다는 것이다.
Python List를 Numpy array로 바꾸고 두 어레이를 더해보기!
```py
num1 = [1, 2, 3, 4, 5, 6]
num2 = [7, 8, 9, 10, 11, 12]
import numpy as np
np_num1 = np.array(num1)
np_num2 = np.array(num2)
print(np_num1+np_num2)
```
```py
[ 8 10 12 14 16 18]
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.