import geopandas as gpd
import plotly.express as px
import json
import pandas as pd
Agg_trans=pd.read_excel('Data_Path')
GrouBy_data=pd.DataFrame(Agg_trans.groupby('State')['Transaction_amount'].sum())
data_df=GrouBy_data.reset_index()
# Load GeoJSON
geo_data = gpd.read_file("Geojson_Path")
# Convert the GeoDataFrame to a GeoJSON
geo_json = json.loads(geo_data.to_json())
# Merge data with the GeoDataFrame
df = geo_data.merge(data_df, left_on='State', right_on='State', how='left')
# choropleth map
fig = px.choropleth(
df,
geojson=geo_json,
featureidkey="properties.State", # Match with the key in GeoJSON properties
locations="State",
color="Transaction_amount",
projection="mercator",
width=900,
height=700
)
fig.update_geos(fitbounds="locations", visible=False)
# Show the map
fig.show()
Result: