
VerticaPy
Python API for Vertica Data Science at Scale
Integrating with GeoPandas¶
As of version 0.4.0, VerticaPy features GeoPandas integration. This allows you to easily export a vDataFrame as a GeoPandas DataFrame, giving you more control over geospatial data.
This example demonstrates the advantages of GeoPandas integration with the 'world' dataset.
In [1]:
from verticapy.datasets import load_world
world = load_world()
display(world)
The 'apply' function of the VerticaPy stats module allows you to apply any Vertica function to the data. Let's compute the area of each country.
In [2]:
import verticapy.stats as st
world["geography"] = st.apply("stv_geography", world["geometry"])
world["geography"].astype("geography")
world["area"] = st.apply("st_area", world["geography"])
display(world)
We can now export our vDataFrame as a GeoPandas DataFrame.
In [3]:
df = world.to_geopandas(geometry = "geometry")
display(df)
From there, we can draw any geospatial object.
In [4]:
ax = df.plot(edgecolor = "black",
color = "white",
figsize = (10, 9))
In [5]:
from verticapy.datasets import load_cities
# Loading the cities dataset
cities = load_cities()
import verticapy.stats as st
import matplotlib.pyplot as plt
# Creating a Matplotlib figure
fig, ax = plt.subplots()
fig.set_size_inches(11, 8)
# Extracting longitude and latitude
cities["lon"] = st.apply("st_x", cities["geometry"])
cities["lat"] = st.apply("st_y", cities["geometry"])
# Drawing the data on a Map
ax = cities.scatter(["lon", "lat"], ax = ax)
df.plot(edgecolor = "black",
color = "white",
ax = ax)
Out[5]:
You can also draw maps using the 'geo_plot' method. The dataset used in the following cell is available here.
In [6]:
import verticapy as vp
# Africa Dataset
africa = vp.read_csv("data/africa_education.csv")
africa_world = load_world()
africa_world = africa_world[africa_world["continent"] == "Africa"]
ax = africa_world["geometry"].geo_plot(color = "white",
edgecolor='black',)
# displaying schools in Africa
africa.scatter(["lon", "lat"],
catcol = "country_long",
ax = ax,
with_others = False,
max_cardinality = 20)
Out[6]: