Choropleth displaying problem

Hello All,

Im trying to make a simple choropleth diagram for a branch network in a country via plotly express. my aim is to create a map that shows total fee amount by city and be able to break it down by Fee names. when i run the code i can see the map and its colorized but i cant see the sum, I also wasnt able to break it down by fee types. Any suggestions ?

I’ve searched it via forums but i couldnt find any answers, Im also starter and built my code from exercises that i foun on the internet

Thanks in advance

from urllib.request import urlopen
import json
with open('tr-cities-utf8.json', encoding= "utf8") as response:
    id = json.load(response)
import pandas as pd
df = pd.read_csv("komisyon5.csv",encoding ='utf8', dtype={"Fee": int})


import plotly.express as px

fig = px.choropleth_mapbox(df, geojson= id, locations='Id', color= "Fee", 
                           color_continuous_scale="Viridis",
                           range_color=(0, 5000),
                           mapbox_style="carto-darkmatter",
                           zoom=3, center = {"lat": 41.0902, "lon": 28.7129},
                           opacity=0.5,
                          )

dropdown_buttons =[{'label': 'A', 'method' : 'restyle', 'args': [{'visible': [True, False, False]}, {'title': 'A'}]},
                   {'label': 'B', 'method' : 'restyle', 'args': [{'visible': [False, True, False]}, {'title': 'B'}]},
                   {'label': 'C', 'method' : 'restyle', 'args': [{'visible': [True, False, True]}, {'title': 'C'}]}]

fig.update_layout({'updatemenus':[{'type': 'dropdown', 'showactive': True, 'active': 0, 'buttons': dropdown_buttons}]})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

I found the solution, just posting the answer for people who might have the same problem. the problem was not in the code but in the data, if you are using plotly express your csv has to different category information in each line, so you need to use “a long data”

I ve adjusted the csv, updated the dropdown and it worked just fine,

This is the post that helped me to solve my problem (https://towardsdatascience.com/visualization-with-plotly-express-comprehensive-guide-eb5ee4b50b57)

   from urllib.request import urlopen
import json
with urlopen("https://raw.githubusercontent.com/Babolius/project/62fef3b31fa9e34afb055e493de107d89a50a889/tr-cities-utf8.json") as response:
    id = json.load(response)
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/Babolius/project/main/komisyon5.csv",encoding ='utf8', dtype={"Toplam": int})
df.groupby(['ID']).sum()


import plotly.express as px


fig = px.choropleth_mapbox(df, geojson= id, locations= 'ID', color= "Toplam",
                           color_continuous_scale="Viridis",
                           range_color=(0, 1000000),
                           mapbox_style="carto-darkmatter",
                           zoom=3, center = {"lat": 41.0902, "lon": 28.7129},
                           opacity=0.5,
                          )

dropdown_buttons =[{'label': 'A', 'method' : 'restyle', 'args': [{'z': [df["A"]]}, {'visible': [True, False, False, False, False, False]}, {'title': 'A'}]},
                   {'label': 'B', 'method' : 'restyle', 'args': [{'z': [df["B"]]}, {'visible': [False, True, False, False, False, False]}, {'title': 'B'}]},
                   {'label': 'C', 'method' : 'restyle', 'args': [{'z': [df["C"]]}, {'visible': [False, False, True, False, False, False]}, {'title': 'C'}]},
                   {'label': 'D', 'method' : 'restyle', 'args': [{'z': [df["D"]]}, {'visible': [False, False, False, True, False, False]}, {'title': 'D'}]},
                   {'label': 'E', 'method' : 'restyle', 'args': [{'z': [df["E"]]}, {'visible': [False, False, False, False, True, False]}, {'title': 'E'}]},
                   {'label': 'Toplam', 'method' : 'restyle', 'args': [{'z': [df["Toplam"]]}, {'visible': [False, False, False, False, False, True]}, {'title': 'Toplam'}]}]

fig.update_layout({'updatemenus':[{'type': 'dropdown', 'showactive': True, 'active': 0, 'buttons': dropdown_buttons}]})

fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()