지식창고/DB

[DB - Python] MySQL - 파이썬 연동, 조회

Developer D 2020. 10. 13. 16:45
반응형

test database
결과

 

 

import pymysql
import numpy
import pandas as pd

conn = pymysql.connect(host="HOST IP 주소 ", port=3306, user=' DB USER ID', passwd='DB USER PW', db='DATABASE NAME', charset='utf8',
cursorclass=pymysql.cursors.DictCursor)

cursor = conn.cursor()

cursor.execute("select * from test")

res= cursor.fetchall()

print(res) #제이슨 형식

df = pd.DataFrame(res)

print(df.describe())

print(df.dtypes)

print(df.shape)

반응형