Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create PolyLines though a loop in Folium / Pandas

I try to create multiple lines from a Dataframe in JupyterLab while looping. I have created the following code but every time I try to run it, my Jupyter Notebook crashes and tell me that the Kernel has died. What am I missing here?

m = folium.Map(location=[VstBreitengrad, VstLängengrad], max_zoom=20, zoom_start=5)

for index, row in dfFilter.iterrows():

    Breitengrad = row["Breitengrad_x"]
    Längengrad = row["Längengrad_x"]

    coordinates = [
                [Breitengrad, Längengrad],
                [20, 20]
    ]
               
    folium.PolyLine(
            locations=coordinates,
            color="#FF0000",
            weight=5,
    ).add_to(m)

m

Breitengrad_x and Längengrad_x are the columns in the dataframe from where I’ll get the coordinates. If I hardcode the coordinates like

Breitengrad = 50 #row["Breitengrad_x"]
Längengrad = 20 #row["Längengrad_x"]

the code runs without a problem. Thanks a lot for your ideas / solutions.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming the dtype of Breitengrad_x is int64, row["Breitengrad_x"] will give you a value of type numpy.int64. That’s what may be causing the problem, since your code runs with the hardcoded values.

Tox fix it, try converting the values into regular int:

    ...
    Breitengrad = int(row["Breitengrad_x"])
    Längengrad = int(row["Längengrad_x"])
    ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading