Latitude/hardness recall function

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

csv = pd.read_csv('Coffee shop status.csv')

address = csv['Address']

for i in range(len(address)):

    a = address[i].split(' ')
    address[i] = " ".join(a[0:4])

geo_local = Nominatim(user_agent='South Korea')

def geocoding(address):

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

latitude = [ ]
longitude = [ ]

for i in address:

            latitude.append(geocoding(i)[0])
            longitude.append(geocoding(i)[1])

address_df = pd.DataFrame({'Mission':csv['Mission'], 
                           'Branch name':csv['Branch name'],
                           'Address':csv['Address'],
                           'Address':address, 'latitude':latitude':longitude})

address_df.to_csv('lati_longi_csv') 

--------------- When executing code --------------------

AttributeError: 'NoneType' object has no attribute 'latitude' error occurs.

We'll take the latitude and longitude

point when importing, / If you can't find the hardness on the jusogap ;

the [0, 0].

If you want to display latitude/longitude only if you can recall it,

How do I modify the code?

***Conclusion: Depending on the address, the latitude/hardness is called, but the value that cannot be found is returned as a code *

python

2022-09-20 11:07

1 Answers

What you're looking for is a process commonly referred to as null merge. Your case does not have geo, so seems to be the best.

x_y = [geo.latitude, geo.longitude] if geo is not None else [0, 0]


2022-09-20 11:07

If you have any answers or tips


© 2022 pinfo. All rights reserved.