Series : 1차원 데이터 구조로 '인덱스 + 값'으로 이루어져있다.
DataFrame : 2차원 데이터 구조(엑셀의 표 같은 구조)로 여러 개의 Series가 모여서 만들어진다.
s = pd.Series(data = [1000,2000,"3000"],
index = ["메로나","구구콘",-1])
print(s)
print(s.iloc[0])
print(s.iloc[1])
print(s.iloc[2])
print(s.iloc[-1])
print(s.loc["메로나"])
print(s.loc["구구콘"])
print(s.loc["하겐다즈"])
맨 마지막 줄에서 KeyError가 발생한다.
"하겐다즈"란 인덱스가 Series에 존재하지 않기 때문이다.
if "하겐다즈" in s.index:
print(s.loc["하겐다즈"])
else:
print("해당 인덱스가 존재하지 않습니다.")
이런 식으로 loc 사용 전 인덱스 존재 여부를 확인하면 에러가 나지 않는다.
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([
[1],
[2],
[3]
])
print(arr2.shape)
result = arr1 + arr2
print(result)

Broadcasting은 크기가 다른 배열 간의 연산을 자동으로 확장하여 수행하는 기능이다.
아래 조건을 만족하면 Broadcasting이 가능하다.
import numpy as np
a = np.array([1, 2, 3])
b = 2 # 스칼라 (0차원)
result = a + b
print(result)
# 출력 : [3 4 5]
a = np.array([[1, 2, 3],
[4, 5, 6]]) # (2,3)
b = np.array([10, 20, 30]) # (3,)
result = a + b
print(result)
# 출력 : [[11 22 33]
# [14 25 36]]
a = np.array([[1],
[2],
[3]]) # (3,1)
b = np.array([10, 20, 30]) # (3,)
result = a + b.reshape(3,1) # b의 shape을 (3,1)로 변경
print(result)
# 출력 : [[11]
# [22]
# [33]]
select ename
from emp
where ename like '_A%';
select ifnull(mgr, "없음") as mgr
from emp;
select empno, ename
from emp
where length(ename) >= 5;
select empno, ename, sal
from emp
where sal between 1000 and 2000
order by sal desc;
select ename, comm
from emp
where comm is null;
select hiredate, empno
from emp
where hiredate like '1981%';
세줄요약:
1. 넘파이에서 브로드캐스팅이 일어나는 케이스를 잘 이해 하자.
2. 판다스란 = 시리즈 + 데이터프레임 이다.
3. 오라클 = nvl함수이고 이고 mysql은 ifnull 이다.
