pandas로 빠르고 간편한 데이터 적재
Amany Mahfouz
Instructor
SELECT DISTINCT로 가져옵니다SELECT DISTINCT [column names] FROM [table];
SELECT DISTINCT * FROM [table];
/* 고유한 도로 주소와 자치구 가져오기 */
SELECT DISTINCT incident_address,
borough
FROM hpd311calls;
SUMAVGMAXMINCOUNTSUM, AVG, MAX, MINSELECT AVG(tmax) FROM weather;
COUNTSELECT COUNT(*) FROM [table_name];
SELECT COUNT(DISTINCT [column_names]) FROM [table_name];
GROUP BY로 범주별 요약/* 자치구별 배관(PLUMBING) 민원 건수 */
SELECT borough,
COUNT(*)
FROM hpd311calls
WHERE complaint_type = 'PLUMBING'
GROUP BY borough;
# 데이터베이스 엔진 생성 engine = create_engine("sqlite:///data.db")# 자치구별 배관 민원 건수 쿼리 작성 query = """SELECT borough, COUNT(*) FROM hpd311calls WHERE complaint_type = 'PLUMBING' GROUP BY borough;"""# 데이터베이스 질의 후 데이터프레임 생성 plumbing_call_counts = pd.read_sql(query, engine)
print(plumbing_call_counts)
borough COUNT(*)
0 BRONX 2016
1 BROOKLYN 2702
2 MANHATTAN 1413
3 QUEENS 808
4 STATEN ISLAND 178
pandas로 빠르고 간편한 데이터 적재