Jupiter address latitude translation code error AttributeError: 'NoneType' object has no attribute 'latitude'

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

https://wonhwa.tistory.com/29?category=996516 Based on this post, I touched that it was the first code in my life. With the help of my friend, I set the environment

import pandas as pd
csv = pd.read_csv('../data/lon.csv',encoding='cp949')
csv
pip install geopy
from geopy.geocoders import Nominatim
geo_local = Nominatim(user_agent='South Korea')

address=csv['Address']
print(address.head())

def geocoding(address):
    geo = geo_local.geocode(address)
    x_y = [geo.latitude, geo.longitude]
    return x_y

It went well so far without any problems, but the problem is next. It was executed exactly like the site mentioned earlier.

latitude = [] 

longitude = []

for i in address:
    latitude.append(geocoding(i)[0])
    longitude.append(geocoding(i)[1])

--

AttributeError                            Traceback (most recent call last)
<ipython-input-26-ede2a66771c9> in <module>
      4 
      5 for i in address:
----> 6     latitude.append(geocoding(i)[0])
      7     longitude.append(geocoding(i)[1])

<ipython-input-25-2c4629605003> in geocoding(address)
      1 def geocoding(address):
      2     geo = geo_local.geocode(address)
----> 3     x_y = [geo.latitude, geo.longitude]
      4     return x_y

AttributeError: 'NoneType' object has no attribute 'latitude'

This error appears. As I mentioned earlier, when I touched this first code in my life, I would really appreciate it if you could tell me as detailed and easy as possible.

jupyter map error python

2022-09-20 11:27

1 Answers

      2     geo = geo_local.geocode(address)
----> 3     x_y = [geo.latitude, geo.longitude]
      4     return x_y

AttributeError: 'NoneType' object has no attribute 'latitude'

If you interpret the error message, The 'NoneType' object has no attribute 'latitude'. That's what it means.

The code this error points to is the code geo.latitude. geo is None Type, and this type of object geo has no attribute latitude. NoneType object is None only.

Then why geo is None in the front geo = geo_local.This is probably because the geocode function returned None in the geocode(address).

It would be a function that returns latitude and longitude for an address, but if the address string contains a string other than an address, or if the geocode function does not know the address given, it seems to return None because it does not know latitude.


2022-09-20 11:27

If you have any answers or tips


© 2022 pinfo. All rights reserved.