Streamlined Data Ingestion with pandas
Amany Mahfouz
Instructor
SELECT *
FROM hpd311calls
SELECT *
FROM hpd311calls
JOIN weather
ON hpd311calls.created_date = weather.date;
table.column
) when working with multiple tables/* Get only heat/hot water calls and join in weather data */
SELECT *
FROM hpd311calls
JOIN weather
ON hpd311calls.created_date = weather.date
WHERE hpd311calls.complaint_type = 'HEAT/HOT WATER';
/* Get call counts by borough */
SELECT hpd311calls.borough,
COUNT(*)
FROM hpd311calls
GROUP BY hpd311calls.borough;
/* Get call counts by borough
and join in population and housing counts */
SELECT hpd311calls.borough,
COUNT(*),
boro_census.total_population,
boro_census.housing_units
FROM hpd311calls
GROUP BY hpd311calls.borough
/* Get call counts by borough
and join in population and housing counts */
SELECT hpd311calls.borough,
COUNT(*),
boro_census.total_population,
boro_census.housing_units
FROM hpd311calls
JOIN boro_census
ON hpd311calls.borough = boro_census.borough
GROUP BY hpd311calls.borough;
query = """SELECT hpd311calls.borough,
COUNT(*),
boro_census.total_population,
boro_census.housing_units
FROM hpd311calls
JOIN boro_census
ON hpd311calls.borough = boro_census.borough
GROUP BY hpd311calls.borough;"""
call_counts = pd.read_sql(query, engine)
print(call_counts)
borough COUNT(*) total_population housing_units
0 BRONX 29874 1455846 524488
1 BROOKLYN 31722 2635121 1028383
2 MANHATTAN 20196 1653877 872645
3 QUEENS 11384 2339280 850422
4 STATEN ISLAND 1322 475948 179179
SELECT
FROM
JOIN
WHERE
GROUP BY
Streamlined Data Ingestion with pandas