A production-quality Python pipeline for visualizing real estate listing data from Zonaprop on a neighborhood-level map of Buenos Aires.
- Data Cleaning: Normalizes prices to USD, validates coordinates, and standardizes neighborhood names
- Neighborhood Aggregation: Calculates average prices, price per square meter, and listing counts per neighborhood
- GeoJSON Integration: Joins aggregated data with neighborhood polygon geometries
- Interactive Mapping: Creates beautiful folium maps with choropleth visualization and optional individual listing points
pip install -r requirements.txtpython pipeline.py --input scraped_data.csv --geojson barrios_caba.geojson# Show individual listings as points
python pipeline.py --input scraped_data.csv --geojson barrios_caba.geojson --show-listings
# Use custom exchange rate
python pipeline.py --input scraped_data.csv --geojson barrios_caba.geojson --usd-rate 1200.0
# Use different price column for coloring
python pipeline.py --input scraped_data.csv --geojson barrios_caba.geojson --price-column avg_price_per_sqm_usd
# Custom output file
python pipeline.py --input scraped_data.csv --geojson barrios_caba.geojson --output my_map.html--input: Path to input CSV file (default:scraped_data.csv)--geojson: Path to GeoJSON file with Buenos Aires neighborhoods (optional, will attempt to download if not provided)--output: Path to output HTML map file (default:buenos_aires_map.html)--usd-rate: USD to ARS exchange rate for currency conversion (default: 1000.0)--show-listings: Show individual listings as semi-transparent points on the map--price-column: Column to use for coloring neighborhoods (default:avg_price_usd)
You need a GeoJSON file with Buenos Aires neighborhood polygons. Here are some sources:
-
Buenos Aires Open Data Portal: https://data.buenosaires.gob.ar/
- Search for "barrios" or "comunas"
- Look for datasets with polygon geometries
-
OpenStreetMap: Extract neighborhood boundaries using Overpass API or download from OSM extracts
-
GitHub: Search for "buenos aires geojson" or "caba barrios geojson"
-
Government Sources: Buenos Aires city government may provide official neighborhood boundaries
The GeoJSON should have:
- A column with neighborhood names (common names:
barrio,nombre,name,BARRIO) - Polygon geometries in WGS84 (EPSG:4326) coordinate system
The CSV file should contain at minimum:
- Price: Column named
price_amount,price_value, orprice - Currency: Column named
currency_pri,price_type, orcurrency(values: USD, $, ARS, etc.) - Coordinates: Columns named
geo_latitude/geo_longitude,latitude/longitude, orlat/lon - Neighborhood: Column named
neighborhood_json,neighborhood, orbarrio - Area (optional): Column named
m2_total,total_area,m2_covered, orcovered_area
The pipeline generates:
- Interactive HTML Map (
buenos_aires_map.htmlby default):- Neighborhood polygons colored by average price
- Hover tooltips with neighborhood statistics
- Optional individual listing points
- Color scale legend
- Multiple base map layers (OpenStreetMap, CartoDB)
The pipeline is organized into modular components:
data_cleaning.py: Cleans and normalizes raw listing dataaggregation.py: Aggregates listings by neighborhoodgeojson_handler.py: Loads and joins GeoJSON datamapping.py: Creates interactive folium mapspipeline.py: Main orchestration script
The map will show:
- Neighborhood polygons with colors representing average prices (darker = higher price)
- Tooltips showing neighborhood name, average price, listing count, and price per square meter
- Individual listings (if
--show-listingsis used) as semi-transparent points - Legend explaining the color scale
The pipeline gracefully handles:
- Missing neighborhoods in GeoJSON (reports unmatched neighborhoods)
- Missing neighborhoods in listings (keeps all GeoJSON neighborhoods)
- Invalid coordinates (filters out listings outside Buenos Aires bounds)
- Invalid prices (filters out unrealistic values)
- Missing area data (aggregates price-only statistics)
- The default USD to ARS exchange rate is 1000.0. Update this with
--usd-ratefor current rates. - Neighborhood name matching uses fuzzy normalization (lowercase, no accents) to handle variations.
- Coordinates are validated to be within Buenos Aires bounds (approximately -34.3 to -34.8 latitude, -58.2 to -58.6 longitude).