Plotly express shows Invalid property for latitude for choropleth map plot for python

251 Views Asked by At

I am using these dataset " dataset tempat perlancongan Malaysia.csv" . In that I'm Passing the latitude and longitude for plotting the plot plot for spatial coordinate vs numerical feature .

error I got =

Value Error: Invalid property specified for object of type plotly.graph_objs.Choropleth: 'lat'

1

There are 1 best solutions below

0
Rob Raymond On
  • I don't speak Malay so can't fully find data set you partially reference. Have used this one pelancongan data
  • it's appears you have not understood what a choropleth is. A choropleth uses polygons as the geometry, not points. From fact you are trying to pass lat and the data I have found provided latitude and longitude your data supports a scatter not a choropleth
import requests, io
import plotly.express as px

# https://www.data.gov.my/data/en_US/dataset/lokasi-tempat-pelancongan-mengikut-daerah-di-negeri-selangor/resource/18b5c1e0-e362-41a2-935c-c35795df9d17
df = pd.read_csv(
    io.StringIO(
        requests.get(
            "https://www.data.gov.my/data/en_US/datastore/dump/18b5c1e0-e362-41a2-935c-c35795df9d17"
        ).text
    )
)

px.scatter_geo(df, lat="LATITUDE", lon="LONGITUDE", hover_data=["NAMA"]).update_layout(
    geo_scope="asia", geo_fitbounds="locations"
)

enter image description here

mapbox ***

px.scatter_mapbox(
    df,
    lat="LATITUDE",
    lon="LONGITUDE",
    hover_data=["NAMA"],
    mapbox_style="carto-positron",
)

enter image description here