0

i am trying to handle data in python using pandas , I have this data enter image description here

  import folium
    import pandas
    mapp = folium.Map(location=[19.997454,73.789803], zoom_start=6, tiles="Stamen Terrain" )
    fg = folium.FeatureGroup(name="my map")
    
    df=pandas.read_csv("volcanoes.txt")
    cordinates="[" + df["LAT"].astype(str) + "," + df["LON"].astype(str) +"]"
    
    for i in cordinates:
        fg.add_child(folium.Marker(location=i,popup="hey jayesh , welcome to Nashik",icon=folium.Icon(color="green")))
    
    mapp.add_child(fg)
    
    mapp.save("jay1.html")


> Windows PowerShell Copyright (C) Microsoft Corporation. All rights
> reserved.
> 
> Try the new cross-platform PowerShell https://aka.ms/pscore6
> 
> PS C:\Users\DELL\OneDrive\Desktop\python\volcano> &
> C:/Users/DELL/AppData/Local/Programs/Python/Python39/python.exe
> c:/Users/DELL/OneDrive/Desktop/python/volcano/jayesh.py Traceback
> (most recent call last):   File
> "c:\Users\DELL\OneDrive\Desktop\python\volcano\jayesh.py", line 10, in
> <module>
>     fg.add_child(folium.Marker(location=i,popup="hey jayesh , welcome to Nashik",icon=folium.Icon(color="green")))   File
> "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\folium\map.py",
> line 277, in __init__
>     self.location = validate_location(location) if location else None   File
> "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\folium\utilities.py",
> line 50, in validate_location
>     raise ValueError('Expected two (lat, lon) values for location, ' ValueError: Expected two (lat, lon) values for location, instead got:
> '[48.7767982,-121.810997]'. PS
> C:\Users\DELL\OneDrive\Desktop\python\volcano>
DYZ
  • 55,249
  • 10
  • 64
  • 93
Jayesh Thakkar
  • 113
  • 2
  • 12
  • Please supply the expected [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) (MRE). We should be able to copy and paste a contiguous block of your code, execute that file, and reproduce your problem along with tracing output for the problem points. This lets us test our suggestions against your test data and desired output. Off-site links and images of text are not acceptable; we need your question to be self-contained, in keeping with the purpose of this site. – Prune Jun 05 '21 at 00:15
  • Please [include a minimal data frame](https://stackoverflow.com/questions/52413246/how-to-provide-a-reproducible-copy-of-your-dataframe-with-to-clipboard) as part of your MRE. – Prune Jun 05 '21 at 00:15
  • In a quick scan of your error message, I notice that the cited argument is a single list, rather than two separate values. Perhaps you need `*i` instead of `i`? – Prune Jun 05 '21 at 00:17

2 Answers2

0

The problem is with this line:

cordinates="[" + df["LAT"].astype(str) + "," + df["LON"].astype(str) +"]"

You are generating a string literal and passing that in.

Try replacing that line with:

cordinates = [(lat, lon) for lat, lon in zip(df["LAT"],df["LON"])]

This will generate a list of (lat, lon) tuples, which should work. I also don't think you need to cast them to str

myz540
  • 537
  • 4
  • 7
0
**it work for me like his**
import folium
    import pandas
    mapp = folium.Map(location=[19.997454,73.789803], zoom_start=6, tiles="Stamen Terrain" )
    fg = folium.FeatureGroup(name="my map")
    
    df=pandas.read_csv("volcanoes.txt")
    lat=list(df["LAT"])
    lon=list(df["LON"])
    
    for i,j in zip(lat,lon):
        fg.add_child(folium.Marker(location=[i,j],popup="volcanoes",icon=folium.Icon(color="green")))
    
    mapp.add_child(fg)
    
    mapp.save("volcanoes.html")
Jayesh Thakkar
  • 113
  • 2
  • 12