Interactive Table Visualisation¶
In this notebook, you’ll learn how to use UrbanMapper to load a CSV file and visualise it interactively using the TableVisMixin
class. This is a great way to explore your urban data dynamically thanks to Skrub
table viz that you can see at: https://skrub-data.org/stable/.
Let’s dive in! 🚀
Step 1: Initialising UrbanMapper¶
We’ll start by creating an instance of UrbanMapper
. This sets up the environment for loading your CSV data.
import urban_mapper as um
# Initialise UrbanMapper
mapper = um.UrbanMapper()
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import urban_mapper as um 3 # Initialise UrbanMapper 4 mapper = um.UrbanMapper() File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/__init__.py:3 1 from loguru import logger ----> 3 from .mixins import ( 4 LoaderMixin, 5 EnricherMixin, 6 VisualMixin, 7 TableVisMixin, 8 AuctusSearchMixin, 9 PipelineGeneratorMixin, 10 UrbanPipelineMixin, 11 ) 12 from .modules import ( 13 LoaderBase, 14 CSVLoader, (...) 30 PipelineGeneratorFactory, 31 ) 33 from .urban_mapper import UrbanMapper File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/mixins/__init__.py:1 ----> 1 from .loader import LoaderMixin 2 from .enricher import EnricherMixin 3 from .visual import VisualMixin File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/mixins/loader.py:1 ----> 1 from urban_mapper.modules.loader.loader_factory import LoaderFactory 4 class LoaderMixin(LoaderFactory): 5 def __init__(self): File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/__init__.py:1 ----> 1 from .loader import LoaderBase, CSVLoader, ShapefileLoader, ParquetLoader 2 from .imputer import ( 3 GeoImputerBase, 4 SimpleGeoImputer, 5 AddressGeoImputer, 6 ) 7 from .filter import ( 8 GeoFilterBase, 9 BoundingBoxFilter, 10 ) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/loader/__init__.py:3 1 from .abc_loader import LoaderBase 2 from .loaders import CSVLoader, ShapefileLoader, ParquetLoader ----> 3 from .loader_factory import LoaderFactory 5 __all__ = [ 6 "LoaderBase", 7 "CSVLoader", (...) 10 "LoaderFactory", 11 ] File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/loader/loader_factory.py:19 17 from urban_mapper.modules.loader.loaders.csv_loader import CSVLoader 18 from urban_mapper.modules.loader.loaders.parquet_loader import ParquetLoader ---> 19 from urban_mapper.modules.loader.loaders.raster_loader import RasterLoader # Importing RasterLoader of the new raster loader module 20 from urban_mapper.modules.loader.loaders.shapefile_loader import ShapefileLoader 21 from urban_mapper.utils import require_attributes File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/70/src/urban_mapper/modules/loader/loaders/raster_loader.py:2 1 from ..abc_loader import LoaderBase ----> 2 import rasterio 3 from typing import Any 4 import numpy as np ModuleNotFoundError: No module named 'rasterio'
Step 3: Loading Your CSV Data¶
Now, we’ll load your CSV file using UrbanMapper’s loader. Replace "<path>"
with the actual path to your CSV file. We’ll specify longitude and latitude columns to prepare the data for geospatial use. Change appropriately.
# Load CSV data (replace '<path>' with your file path)
csv_loader = mapper.loader.from_huggingface("oscur/taxisvis1M", number_of_rows=1000, streaming=True).with_columns("pickup_latitude", "pickup_longitude")
data = csv_loader.load()
data.head() # Preview the first few rows
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[2], line 2 1 # Load CSV data (replace '<path>' with your file path) ----> 2 csv_loader = mapper.loader.from_huggingface("oscur/taxisvis1M", number_of_rows=1000, streaming=True).with_columns("pickup_latitude", "pickup_longitude") 3 data = csv_loader.load() 4 data.head() # Preview the first few rows NameError: name 'mapper' is not defined
Step 4: Displaying the Table Interactively¶
With your data loaded, let’s use TableVisMixin
to create an interactive table. This will allow you to sort, filter, and explore the data dynamically. We’ll display the first 10 rows, sorted by longitude.
Click on some features / columns and use the nice interactive viz by Skrub.
# Create an instance of TableVisMixin
vis = mapper.table_vis.interactive_display(
dataframe=data,
n_rows=10,
title="Interactive Urban Data Report",
verbose=1
)
vis
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[3], line 2 1 # Create an instance of TableVisMixin ----> 2 vis = mapper.table_vis.interactive_display( 3 dataframe=data, 4 n_rows=10, 5 title="Interactive Urban Data Report", 6 verbose=1 7 ) 8 vis NameError: name 'mapper' is not defined
Wrapping Up¶
That’s it! 🎈 You’ve successfully loaded your CSV data with UrbanMapper and visualised it interactively using TableVisMixin
. This interactive display makes it easy to explore your dataset. Feel free to tweak the n_rows
, order_by
, or other parameters to customise the view!