I need help with missing code
python
# In this question, we are asked to find lattitude (lat.) andlongitude (lng.) of different cities that our customers are comingfrom. The list of cities are stored in Cities.txt. # We use geopy to get lat and lat of different cities, and at theend we store them in the results.txt file. # # # This HW can be applied in real businesses. You can get theaddress of customers and use geopy to find lat and lng and thenplot their location on maps such as ipyleaflet to show each ofthese points on the map to find the area with more density.#
# In[1]:
get_ipython().system('pip install requests ')
# requests is an excellent library to get data from websites, formore info, you may check the following website. #
# In[2]:
get_ipython().system('pip install folium')
# folium is a map visualization library. see more detail here#http://folium.readthedocs.io/en/latest/ ... ng-started
# In[4]:
get_ipython().system('pip3 install geopy')
# geopy makes it easy for Python developers to locate thecoordinates of addresses, cities, countries, and landmarks acrossthe globe using third-party geocoders and other data sources.# # Check more info here: https://pypi.org/project/geopy/
# In[54]:
#initiating the mapimport foliumfrom geopy.geocoders import NominatimMymap = folium.Map(location=[32.7766642 ,-96.79698789999999],zoom_start=9)geolocator = Nominatim(user_agent="BUSA523HW5")
# the above command plots a map where the startingcordinate is [32.7766642 , -96.79698789999999] and# zoom is 9 (the larger the number, the more focused on the givenlocation).
# In[66]:
filename = 'Cities.txt' # this file has the list ofcities popfile = open(filename, 'r') # open the file in readingmodeline = popfile.readline().strip('\n') # read the first linewhile line !='': words = line.split(',') city=words[0]+', '+words[1] location = geolocator.geocode(city) latt = location.latitude lngg = location.longitude folium.Marker([latt, lngg]).add_to(Mymap) # add apoint on the map. line = popfile.readline().strip('\n') # read thefirst lineMymap
# In[ ]:
result = 'result.txt' # this file will recordethe results Profile2 = open(result, '?') # open the file in writing modefilename = 'Cities.txt' popfile = open(filename, '?') # open the file in readingmodeline = popfile.'?'() # read the first lineline = line.strip('?') # remove the enter from end of thelinewhile line !='?': # the while loop should loop over alllines, it stops at the end of the file. words = line.split(',') # s city=words[0]+', '+words[1] location = geolocator.geocode(city) latt = location.latitude lngg = location.longitude folium.Marker([latt, lngg]).add_to(Mymap) # add apoint on the map. GeoLoc= '?'(line.strip('\n')) +':'+ '?'(latt) +' '+'?'(lngg) # all '?' need to be replaced by the same function! # convert to a datatype that wirte can work withit! Profile2.write(GeoLoc+' \n') line = popfile.'?'().strip('\n') # read the nextlineMymap # shows the map.
I need help with missing code python # In this question, we are asked to find lattitude (lat.) and longitude (lng.) of d
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am