PL/SQL
IF 조건문 THEN
창일때 수행하는 로직
END IF;
IF 조건문 TEHN
참일때 수행하는 로직
ELSE
거짓일때 수행하는 로직
END IF;
IF 조건문1 THEN
조건문1이 참일때 수행하는 로직
ELSIF 조건문2 THEN
조건문2이 참일때 수행하는 로직
ELSIF 조건문3 THEN
조건문3이 참일때 수행하는 로직
ELSE
거짓일때 수행하는 로직
END IF;
IF 조건문:
참일때 수행하는 로직
IF 조건문:
참일때 수행하는 로직
ELSE:
거짓일때 수행하는 로직
IF 조건문 1:
조건문1이 참일때 수행하는 로직
ELIF 조건문2:
조건문2이 참일때 수행하는 로직
ELSE:
거짓일때 수행하는 로직
예)
if {}:
print('참')
else:
print('거짓')

x = 8
if x>10 or x%2 == 0:
print('참')
else:
print('거짓')

num = 95
if 90 <= num <= 100:
grade = 'A'
elif 80 <= num < 90:
grade = 'B'
elif 70 <= num < 80:
grade = 'C'
else:
grade = 'F'
print('점수 : {0} 학점 : {1}'.format(num,grade))
print('점수 : %s 학점 : %s'%(num,grade))
print(f'점수 : {num} 학점 : {grade}')

sal = 1000
comm = None #null
sal * 12 + comm
-- 이렇게 하면 오류가 발생한다.
if comm == None:
annnual_salary = sal * 12
else:
annnual_salary = sal * 12 + comm
print(annual_salary)

참값 if 조건문 else 거짓sal = 1000
comm = None
annual_salary = sal * 12 if comm is None else sal * 12 + comm
print(annual_salary)

while 조건문:
반복 수행할 문장
i = 1
while i <= 10:
print(i)
i += 1 # i = i + 1

i = 0
hap = 0
while i <= 100:
i += 3
if i >= 100:
break # 반복분을 중단하는 문
else:
print(i)
hap += i
print(hap)
i = 1
while i <= 10:
if == 4 or i ==8
i += 1
continue
else:
print(i)
i += 1

dan = 2
while dan <= 9:
i = 1
while i <= 9:
print(f'{dan} * {i} = {dan * i}')
i += 1
dan += 1
for 변수 in (리스트,튜플,집합,딕셔너리,문자열):
반복수행할 문장
x = ['oracle','ibm','ms']
for i in x:
print(i.upper())

x = [(1,2),(3,4),(5,6)]
for i in x:
print(i)
for i,j in x:
print(i)
print(j)

for i in range(1,101):
print(i)
for i in range(1,11):
if i == 4 or i == 8:
continue
else:
print(i)

for dan in range(2,10):
for i in range(1,10):
print(f'{dan} * {i} = {dan*i}')
from pandas import Series,DataFrameimport pandas as pdlst = [1,2,3,4,5]
type(lst)
lst + 100
-- 오류발생한다.
--해결방법
new_lst = []
for i in lst:
new_lst.append(i+100)
new_lst = [i + 100 for i in lst]
import pandas
from pandas import Series,DataFrame
x = Series([1,2,3,4,5])
print(x)

x + 100

x.astype

x1 = Series(['1',2,3,4,5])
print(x1)

x1 + 100 # 문자타입은 연산작업할 수 없다. 오류발생
astype('변경타입')
x1 = x1.astype('int64')
print(x1)

x1 + 100

x1.index

x1.values

print(x1[0])
print(x1[1])

x1[0:3] #[시작인덱스 : 끝인덱스 -1]
Series 값 수정
x1[0] = 100
x1
Series 값 추가
x1[5] = 500
Series 값 삭제
del x1[5]
x1
df = DataFrame([[1,2,3],
[4,5,6],
[7,8,9]])
df

type(df)

data = {'도시' : ['서울','부산','강원','인천'],
'인구수' : [500,400,200,300]}
data

df = DataFrame(data)
df

.info()
df.info()

.columns : 컬럼 정보
.index : 인덱스 정보
.values : 값정보
employees = pd.read_csv('C:/Temp/employees.csv')
departments = pd.read_csv('C:/Temp/departments.csv')
출려 행 보기
employees.shape #(행수, 열수)
employees.head() # 상위 5행 출력
employees.head(10) # 상위 10행 출력
employees.tail() # 하위 5행 출력
employees.tail(10) # 하위 10행 출력
출력할 수 있는 컬럼의 수 확인
pd.options.display.max_columns
pd.get_option('display.max_columns')
출력할 수 있는 컬럼의 수 설정
pd.set_option('display.max_columns',11)

출력할 수 있는 컬럼의 수를 기본값으로 설정
pd.reset_option('display.max_columns')

출력할 수 있는 행의 수 확인
pd.options.display.max_rows
pd.get_option('display.max_rows')

출력할 수 있는 행의 수 설정
pd.set_option('display.max_rows',200)

출력할 수 있는 컬럼의 수를 기본값으로 설정
pd.reset_option('display.max_rows')
특정 컬럼값만 확인
employees['EMPLOYEE_ID']

True or False인 값 확인
employees['EMPLOYEE_ID']==100

조건이 True인 row만 확인
employees[employees['EMPLOYEE_ID']==100]

조건이 True인 row의 특정 컬럼만 조회
employees[employees['EMPLOYEE_ID']==100][['LAST_NAME','SALARY']]

employee_id가 100인 row의 last_name, salary 컬럼만 출력
employees[['LAST_NAME','SALARY']][employees['EMPLOYEE_ID']==100]

salary값이 10000 이상인 row 출력
employees[employees['SALARY'] >= 10000]
employees.loc[employees['EMPLOYEE_ID']==100,]

employees.loc[employees['EMPLOYEE_ID']==100,'LAST_NAME']

employees.loc[employees['EMPLOYEE_ID']==100,['LAST_NAME','SALARY']]

x = employees[employees['SALARY'] >= 10000][['LAST_NAME','SALARY','DEPARTMENT_ID']]
x.sort_values(by='DEPARTMENT_ID') # 기본값은 오름차순
x.sort_values(by='DEPARTMENT_ID',ascending=True)
x = employees[employees['SALARY'] >= 10000][['LAST_NAME','SALARY','DEPARTMENT_ID']]
x.sort_values(by='DEPARTMENT_ID',ascending=False)
x = employees[employees['SALARY'] >= 10000][['LAST_NAME','SALARY','DEPARTMENT_ID']]
result = x.sort_values(by=['DEPARTMENT_ID','SALARY'], ascending=[False,True])
result

-- 변수에 결과값 입력
result = x.sort_values(by='DEPARTMENT_ID',ascending=False)
result.reset_index()# 미리보기, 기존인덱스가 컬럼으로 추가되었다.

result = result.reset_index(drop=True)

employees[(employees['EMPLOYEE_ID'] == 100) | (employees['EMPLOYEE_ID']==101)]

employees[employees['EMPLOYEE_ID'].isin([100,101])]

employees[~employees['EMPLOYEE_ID'].isin([100,101])]
employees[employees['COMMISSION_PCT'].isnull()]
employees[~employees['COMMISSION_PCT'].isnull()]
employees[employees['COMMISSION_PCT'].isnull()&((employees['SALARY']>=5000)&(employees['SALARY']<=10000))]
employees['LAST_NAME'].str.len()

employees['LAST_NAME'].str.len() #문자열의 길이를 반환합니다.
employees['LAST_NAME'].str.upper() #문자열을 대문자로 변환합니다.
employees['LAST_NAME'].str.lower() #문자열을 소문자로 변환합니다.
employees['LAST_NAME'].str.capitalize() #문자열의 첫 글자만 대문자로 변환합니다
employees['LAST_NAME'].str.title() #각 단어의 첫 글자를 대문자로 변환합니다
employees['LAST_NAME'].str.swapcase() #대문자는 소문자로, 소문자는 대문자로 변환합니다
employees['LAST_NAME'].str.findall('a') #문자열에서 특정 패턴('a')을 찾아 리스트로 반환합니다
employees['LAST_NAME'].str.find('a')
employees['LAST_NAME'].str.contains('a')
employees['LAST_NAME'].str.contains('a',case=True) # 대소문자구분(기본값)
employees['LAST_NAME'].str.contains('a',case=False) # 대소문자구분하지 않고 찾는다.
employees['LAST_NAME'].str.get(0)
employees['LAST_NAME'].str.get(1)
employees['LAST_NAME'].str.get(2).isin(['a','e'])
employees['LAST_NAME'].str.slice(start=0,stop=2)

employees['LAST_NAME'].str.pad(width=20,side='left')

employees['LAST_NAME'].str.pad(width=20,side='left',fillchar='_')

employees['LAST_NAME'].str.center(width=20,fillchar='_')

obj = Series([2,3,4,5,6,None])
obj
obj.sum()
obj.sum(skipna=True) # NaN(null)제거 기본값
obj.sum(skipna=False)


obj.mean() #평균
obj.median() #중앙값

obj.var() #분산
obj.std() #표준편차
obj.max() #최대값
obj.min() #최소값
obj.idxmax() #최대값의 인덱스
obj.argmax()
obj.idxmin() #최소값의 인덱스
obj.argmin()
obj.cumsum() #누적합
obj.cumprod() #누적곱