I have a GeoPandas dataframeGeoDataFrame:
import geopandas as gpd
import numpy as np
df = \
gpd.GeoDataFrame.from_dict(
dict(
geometry=gpd.points_from_xy([0,1,2],[3,4,5]),
col0=["A","B","C"],
col1=["A","B",np.nan],
col2=["A",np.nan,np.nan],
col3=[np.nan,np.nan,np.nan],
)
).set_crs(4326)
import geopandas as gpd
import numpy as np
df = \
gpd.GeoDataFrame.from_dict(
dict(
geometry=gpd.points_from_xy([0,1,2],[3,4,5]),
col0=["A","B","C"],
col1=["A","B",np.nan],
col2=["A",np.nan,np.nan],
col3=[np.nan,np.nan,np.nan],
)
).set_crs(4326)
I could create the GeoJSON line by line, but that seems tedious. I could theoretically also create a GeoJSON with the null
s, and then produce another GeoJSON without the null
s. In my real world usecase-world use case, I have a lot of different columns, almost all of them have rows almost exclusively set to null
, so this is not very practical. I am also open to using another file format as GeoPandas' output, followed by a convertconversion to GeoJSON by ogr2ogr
for example. The naive
df.to_file("test.gpkg")
df.to_file("test.gpkg")
This thread is on a similar topic, asking how to remove null
s from an existing GeoJSON. I would like to create one without the null
s being there in the first place from the GeoPandas dataframeGeoDataFrame.
What is an easy way to achieve the above described result? What is an easy way to achieve the above-described result?