Skip to content

Instantly share code, notes, and snippets.

@yassineAlouini
Created February 28, 2018 15:55
Show Gist options
  • Select an option

  • Save yassineAlouini/5ee816c7a89ec94a273f22dc5823e11c to your computer and use it in GitHub Desktop.

Select an option

Save yassineAlouini/5ee816c7a89ec94a273f22dc5823e11c to your computer and use it in GitHub Desktop.
Add a random choice column to GeoJSON file
import geopandas as gpd
import numpy as np
# Set a seed for reproducibility
np.random.seed(0)
input_path = 'input/path/to/geojson'
output_path = 'output/path/to/geojson'
choices = [1, 2, 3]
with open(output_path, 'w') as f:
geojson = (gpd.read_file(input_path)
.assign(probafraud=lambda gdf: np.random.choice(choices, len(gdf.index)))
.to_json())
f.write(geojson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment