Geocoding Geopandas

Viewed 85

Hey guys im running into an issue with geocoding. I have a address.csv with hundreds of addresses. I am using the geopandas.tools.geocode and my provider is bing to get zipcodes for all these addresses, but I am unsure on how to extract just the zipcode.

This is my current output.

geometry                                            address
0  POINT (-112.13369 33.84443)  39508 N Daisy Mountain Dr, Anthem, AZ 85086, U...
1  POINT (-112.13671 33.86698)  3640 W Anthem Way, Anthem, AZ 85086, United St...

I just want to extract the zipcode from the address field, and add it into my address.csv file.

1 Answers

One way of doing this it the following:

import pandas as pd
df = pd.read_csv("adresses.csv", sep=";")
print(df)

                geometry  \
0  POINT (-112.13369 33.84443)   
1  POINT (-112.13671 33.86698)   

                                             address  
0  39508 N Daisy Mountain Dr, Anthem, AZ 85086, U...  
1  3640 W Anthem Way, Anthem, AZ 85086, United St... 

and split the column you want by delimiters:

adresses = df['address']
df[['street','town', 'zip', 'other']] =  adresses.str.split(",", n=4, expand=True)
df

which return:

                   geometry  \
0  POINT (-112.13369 33.84443)   
1  POINT (-112.13671 33.86698)   

                                             address  \
0  39508 N Daisy Mountain Dr, Anthem, AZ 85086, U...   
1  3640 W Anthem Way, Anthem, AZ 85086, United St...   

                      street     town        zip           other  
0  39508 N Daisy Mountain Dr   Anthem   AZ 85086   United States  
1          3640 W Anthem Way   Anthem   AZ 85086   United States  

I don't really know how zip-codes work, but if you do not want the AZ (Arizona) you can repeat this by


df[['State','code']]= df.zip.str.split(expand=True,)

Which gives:

                   geometry  \
0  POINT (-112.13369 33.84443)   
1  POINT (-112.13671 33.86698)   

                                             address  \
0  39508 N Daisy Mountain Dr, Anthem, AZ 85086, U...   
1  3640 W Anthem Way, Anthem, AZ 85086, United St...   

                      street     town        zip           other State   code  
0  39508 N Daisy Mountain Dr   Anthem   AZ 85086   United States    AZ  85086  
1          3640 W Anthem Way   Anthem   AZ 85086   United States    AZ  85086  
Related