Quick start guide
Installation¶
pip install map_with_stats
Usage example¶
For visualisation you will need some statistics per hectare. Individual hectares are defined by the X,Y coordinates in the LV03 coordinate system of the bottom-left (=south-west) corner.
- Such data could be for example downloaded from the BFS website.
- For example, one can get population data per hectare for year 2021 from here.
- Download and extract STATPOP2021.csv from the archive.
- Generate the HTML with the map:
import pandas as pd import map_with_stats as mws data_raw = pd.read_csv("STATPOP2021.csv", sep=";") data = data_raw[["RELI", "B21BTOT"]] data = mws.hectare2xy(data, "RELI") # (1)! gdf_stats = mws.create_geo_df_with_hectar_polygons(data, "B21BTOT", crs_out="EPSG:4326") # (2)! # restrict data to the Zürich neighbourhood mask_x = data["X"].between(6700_00, 7000_00) mask_y = data["Y"].between(2330_00, 2630_00) gdf = gdf_stats[mask_x & mask_y] # (3)! # `build_map` is the main helper function that will create a map with a coropleth layer title = "Dummy data" # (4)! map = mws.build_map(gdf, title , "equidistant") map.save("map.html")
hectare2xy
is a helper function that extracts X,Y coordinates from the hectare IDcreate_geo_df_with_hectar_polygons
is a helper function that creates GeoDataFrame with a polygon for each hectare- This step is optional- read FAQ for more details
- Title will be used as data description in the tooltip and colormap