converting output of multiple addresses to table[BUG]
theiman112860 opened this issue · comments
I am trying to use the following code to extract the individual address elements and put them into a dataframe:
from deepparse.parser import AddressParser
address_parser = AddressParser(model_type="bpemb", device=0)
import pandas as pd
# parse multiple addresses
parsed_address = address_parser(
["350 rue des Lilas Ouest Québec Québec G1L 1B6", "350 rue des Lilas Ouest Québec Québec G1L 1B6"])
print(parsed_address) #to look at the output
pd.DataFrame(parsed_address["ParsedAddress"].to_list(), columns=['street_number', 'street_name', 'municipality', 'province','postal_code'])
I get the following error:
pd.DataFrame(parsed_address["ParsedAddress"].to_list(), ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
1 #df3 = pd.DataFrame(columns=['street_number', 'street_name', 'municipality', 'province','postal_code'])
2 #d_list = []
----> 3 pd.DataFrame(parsed_address["ParsedAddress"].to_list(), columns=['street_number', 'street_name', 'municipality', 'province','postal_code'])
4
TypeError: 'ParsedAddress' object is not subscriptable
Any ideas on what I should I do? Thank you!
parsed_address
is a list, meaning thatparsed_address["ParsedAddress"]
means nothing since you cannot subscript using a string. If you want to take the first element of the list, doparsed_address[0]
.- The parse address doesn't have a
to_list()
method, so you will need to manually add a logic to put every address's components in a column.
But, I must say that the idea is good, so I will create a logic to allow parsed addresses to be inputted in Pandas more easily.
I've just released a new version with the new method and an example of how to it (https://deepparse.org/examples/parse_addresses.html).
Yes, you do.
Do, pip install -U deepparse