0

I have a clean data frame which is just a list of addresses. Next used python library called usaddress which returns a list of tuples when I applied them to my pandas column. It returns

[('1234', 'AddressNumber'), ('S', 'StreetNamePreDirectional'), ('Bervely', 
'StreetName'), ('RD', 'StreetNamePostType'),...]

I want to have each left value of each have its own column. I've tried writing a function to get the values of the tuples but I keep getting a list error.

When I write

def addressDirection(df):
    return df[0:2][1:2][0]

IndexError: list index out of range

I can only get the tuples into their own columns and not their values. Here is my code.

def addressDirection(df):
    return df[0:2][1:2]

It returns

[(E, StreetNamePreDirectional)]

Original data

string_addr
1234 S Berverly BLVD KANSAS TX 1235
1234 S Berverly BLVD KANSAS TX 1235
1234 S Berverly BLVD KANSAS TX 1235

After I apply the usaaddress python library. The entire column looks like

   addr_breakdown

[('1234', 'AddressNumber'), ('S', 'StreetNamePreDirectional'), ('Berverly', 'StreetName'), ('BLVD', 'StreetNamePostType'), ('KANSAS', 'PlaceName'), ('MO', 'StateName'), ('1235', 'ZipCode')]

But I just want E. Expected Result:

 Number Direction   Street  PostType    City    State   ZipCode
 1234     S          Berverly BLVD      O-Town   xy       1234

What I have now

 Number Direction   Street  PostType                  City  
  1234         [('S', 'StreetNamePreDirectional') [('Berverly  ','StreetName')]  ....
Zaynaib Giwa
  • 5,366
  • 7
  • 21
  • 26

0 Answers0