def oracle_connect():
name = input('연동할 테이블명을 입력하세요 : ')
#1. 오라클에서 emp 불러오기
import cx_Oracle
import pandas as pd
dsn = cx_Oracle.makedsn("DESKTOP-J31RL48", 1521, 'xe') # IP주소, 포트번호, 서비스 이름 기술
db = cx_Oracle.connect('c##scott','tiger',dsn) # 오라클에 접속할 유저이름과 패스워드 기술
cursor =db.cursor() # SQL 수행결과 데이터를 담을 메모리 이름을 cursor로 선언
sql= "select * from "+name
cursor.execute(sql) # 작성한 쿼리문의 결과가 cursor 메모리에 담김
row = cursor.fetchall() # cursor 메모리에 담긴 결과를 한번에 row 변수에 담는다
#2. 컬럼명 불러오기
colname = cursor.description
#3. 컬럼명만 리스트에 담기
col = []
for i in colname:
col.append(i[0].lower())
result = pd.DataFrame(row) # 데이터를 판다스 데이터 프레임으로 구성한다.
#4. Dataframe에 컬럼명 넣기
result.columns = col
return result
# emp = mysql_connect() 과 같이 변수에 대입하여 사용가능
emp15 = oracle_connect()
# 한글폰트
from matplotlib import font_manager, rc
font = font_manager.FontProperties(fname="c:/Windows/Fonts/malgun.ttf").get_name()
rc('font', family=font)
# 원형그래프 만들기
result = emp15.groupby('telecom')['ename'].count().reset_index()
result.columns = ['통신사','통신사별 인원수']
result['통신사별 인원수'].plot(kind = 'pie',labels = result['통신사'],autopct = '0.0f%%')