Created
February 28, 2018 15:55
-
-
Save yassineAlouini/5ee816c7a89ec94a273f22dc5823e11c to your computer and use it in GitHub Desktop.
Add a random choice column to GeoJSON file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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