0

My assignment is to create an html file of a map. The data has already been given to us. However, when I try to execute my code, I get two errors:

"TypeError: 'str' object cannot be interpreted as an integer" and "KeyError: 'Latitude'"

this is the code that I've written:

import folium
import pandas as pd

cuny = pd.read_csv('datafile.csv')
print (cuny)

mapCUNY = folium.Map(location=[40.768731, -73.964915])

for index,row in cuny.iterrows():
    lat = row["Latitude"]
    lon = row["Longitude"]
    name = row["TIME"]
    newMarker = folium.Marker([lat,lon], popup=name)
    newMarker.add_to(mapCUNY)

out = input('name: ')
mapCUNY.save(outfile = 'out.html')

When I run it, I get all the data in the python shell and then those two errors mentioned above pop up.

Something must have gone wrong, and I'll admit I'm not at all good with this stuff. Could anyone let me know if they spot error(s) or know what I've done wrong?

1 Answers1

0

Generally, "TypeError: 'str' object cannot be interpreted as an integer" can happen when you try to use a string as an integer.

For example:

num_string = "2"
num = num_string+1         # This fails with type error, because num is a string
num = int(num_string) + 1  # This does not fail because num is cast to int

A key error means that the key you are requesting does not exist. Perhaps there is no latitude key, or its misspelled/incorrect capitalization.

Ian A McElhenny
  • 910
  • 8
  • 20