import pandas as pd
df = pd.read_csv('police_station.csv')
df.tail()
import mysql.connector
conn = mysql.connector.connect(
host= "AWS엔드포인트",
port = 3306,
user = "zero",
password = "zerobase",
database = "zerobase"
)
cursor = conn.cursor(buffered=True)
sql = "insert into police_station values (%s, %s)"
for i, row in df.iterrows():
print(tuple(row))
for i, row in df.iterrows():
cursor.execute(sql, tuple(row))
print(tuple(row))
conn.commit()
cursor.execute("select * from police_station")
result = cursor.fetchall()
for row in result:
print(row)
df = pd.DataFrame(result)
df.tail()
import mysql.connector
conn = mysql.connector.connect(
host= "AWS엔드포인트",
port = 3306,
user = "zero",
password = "zerobase",
database = "zerobase"
)
import pandas as pd
df = pd.read_csv("2020_crime.csv", encoding="euc-kr")
df.head()
sql = "insert into crime_status values('2020', %s, %s, %s, %s)"
cursor = conn.cursor(buffered=True)
for i, row in df.iterrows():
cursor.execute(sql, tuple(row))
print(tuple(row))
conn.commit()
cursor.execute("select * from crime_status")
result = cursor.fetchall()
for row in result:
print(row)
df = pd.DataFrame(result)
df.head()
import mysql.connector
conn = mysql.connector.connect(
host= "AWS엔드포인트",
port = 3306,
user = "zero",
password = "zerobase",
database = "zerobase"
);
import pandas as pd
df = pd.read_csv('Seoul_CCTV.csv', encoding="utf-8")
df.head()
sql = "CREATE TABLE cctv (기관명 varchar(8), 소계 int, 2013년도이전 int, 2014년 int, 2015년 int, 2016년 int)"
cursor = conn.cursor(buffered=True)
cursor.execute(sql)
sql = "insert into cctv values (%s, %s, %s, %s, %s, %s)"
cursor = conn.cursor(buffered=True)
for i, row in df.iterrows():
cursor.execute(sql, tuple(row))
print(tuple(row))
conn.commit()
cursor.execute("select * from cctv")
result = cursor.fetchall()
for row in result:
print(row)
df = pd.DataFrame(result)
df.head()
"이 글은 제로베이스 데이터 취업 스쿨 강의를 듣고 작성한 내용으로 제로베이스 데이터 취업 스쿨 강의 자료 일부를 발췌한 내용이 포함되어 있습니다."