Visualizing Marketing Geo Data with PyGWalker: As Simple as Mapping Meteorite Strikes
Bj?rn Thomsen
Marketing Lead at meshcloud.io | Accelerating B2B Market Growth | Professional in Performance Marketing & Web Analytics
Mapping geospatial data, such as website traffic or sales by location, doesn’t necessarily require expensive tools like Tableau or Power BI. Today, I’d like to introduce another feature of PyGWalker, a Python library for exploratory data analysis and visualization, which is particularly well-suited for marketers and web analysts.
By the way: This isn’t my first article on PyGWalker. I covered its basic functionalities, such as importing files, creating bar charts, and saving views, in this article: https://www.dhirubhai.net/pulse/visualizing-marketing-performance-data-tableau-like-library-thomsen-qpvge/
To make things more interesting, instead of using e-commerce data, we’ll work with meteorite impact data today. ?? This dataset comes from the Meteoritical Society and is available on Kaggle: https://www.kaggle.com/datasets/sujaykapadnis/meteorites-dataset
Our goal is to use PyGWalker to create a map that displays meteorite impact locations, with classification information highlighted using color. For this, we’ll use longitude and latitude, which are already included in the dataset and require no additional transformation.
Getting Started
After downloading the dataset as a CSV file, we first need to install PyGWalker (if it’s not already installed). You can do this using the following command:
pip install pygwalker
Next, you can choose to run the analysis in Jupyter Notebook (see my linked article for details) or write the code in your preferred IDE or editor—I personally use Visual Studio Code. For this tutorial, we’ll create a .py file that builds a web application using Streamlit and PyGWalker.
The following Python script will load the meteorite dataset, process it using Pandas, and generate an interactive visualization with PyGWalker. The script imports the required libraries (streamlit, pandas, and pygwalker), configures the app layout for wide display, and uses PyGWalker to create a map-based visualization. It embeds the visualization into a Streamlit web app for interactive exploration, enabling users to see impact locations and classify them by type through color coding.
import streamlit.components.v1 as components
import streamlit as st
import pandas as pd
import pygwalker as pyg
st.set_page_config(layout="wide")
df = pd.read_csv(r"C:\Users\Bj?rnThomsen\Desktop\meteorites.csv", delimiter=',', skiprows=0, low_memory=False)
pyg_html = pyg.to_html(df, dark="light")
components.html(pyg_html, height=1200, scrolling=True)
This approach could just as easily be applied to marketing-related geospatial data, for example to identify regions with high customer density and correlate it with campaign performance metrics. But honestly, meteorite strikes are more interesting. ??
Running the App
To display the visualization, you’ll run the script with Streamlit using the following command:
Visualizing the Data
Once the app is running in your browser (here: https://localhost:8501/), you have first switch the view to "Geographic".
Add with drag & drop 'long' and 'lat' as longitude and latitude to the visualization to display impact locations.
Double-click on 'fall' to mark the impacts' location on our map. And visualize the classification of meteorites by dragging this data onto the 'color' field.
Done. If you want to learn more about mereorite classification, NASA can help you: https://curator.jsc.nasa.gov/education/classification.cfm
To share the visualization with colleagues—whether marketers or, in this case, astronomy enthusiasts—you can export the corresponding Python or JSON code. By the way, in my first article I explain how to import those views into PyGWalker.
Conclusion
Isn't this awesome? You don’t need a Data Scientist (Python / R) or a coffee-sipping, low-code Power BI dashboard artist ??. You’ve got this handled all on your own—like a pro.
PyGWalker makes data analysis and visualization remarkably simple. While libraries like Matplotlib and Folium can be too complex for many marketers and web analysts, and Tableau or Power BI may feel pricey and overly enterprise-focused, PyGWalker offers a lightweight solution requiring only a few lines of code.
Its ability to handle geospatial data, a critical tool for breaking down performance data by region, is another important feature that adds significant value to this powerful tool.