Shannon diversity
[4]:
import pandas as pd
import geopandas as gpd
blocks_gdf = pd.read_pickle('./../../data/saint_petersburg/blocks.pickle')
[5]:
from blocksnet.analysis.diversity import shannon_diversity
diversity_df = shannon_diversity(blocks_gdf)
diversity_df.head()
2025-09-19 17:19:59.971 | INFO | blocksnet.analysis.diversity.shannon.core:shannon_diversity:23 - Calculating Shannon diversity index
100%|██████████| 9533/9533 [00:05<00:00, 1885.73it/s]
[5]:
count_school | count_kindergarten | count_hospital | count_polyclinic | count_pitch | count_swimming_pool | count_theatre | count_museum | count_cinema | count_mall | ... | count_bus_stop | count_pier | count_animal_shelter | count_prison | count_landfill | count_plant_nursery | count_greenhouse_complex | count_warehouse | count | shannon_diversity | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.000000 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0.693147 |
2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.000000 |
3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.000000 |
4 | 1 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | ... | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 4 | 1.039721 |
5 rows × 62 columns
[6]:
blocks_gdf[['geometry']].join(diversity_df).plot('shannon_diversity', legend=True, figsize=(10,8)).set_axis_off()
