![]() |
Dict and Isin - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Dict and Isin (/thread-35439.html) |
Dict and Isin - JonahPython - Nov-03-2021 I need help on data dict and isin codes. Can anybody assist what is the python codes to achieve the results. Thanks. I have two dataframes. Dataframe1 (already convert into dict) Address Driver New York John Los Angeles Tim Dataframe 2 Address 47 W 13th St, New York, NY 10011, USA 1419 Westwood Blvd, Los Angeles | CA 90024-491 What would be the code to generate the following results? Results Address Driver 47 W 13th St, New York, NY 10011, USA John 1419 Westwood Blvd, Los Angeles | CA 90024-491 Tim RE: Dict and Isin - deanhystad - Nov-05-2021 What is Isin? ISIN as is in International Securities Identification Number or "Is this in that?" You want to parse an address to find the city, find a driver for that city, and then append the driver's name to the address? Is that what you want to do? An easy way is to search for all the keys in your driver database. drivers = { "John":"New York", "Tim":"Los Angeles" } addresses = [ "47 W 13th St, New York, NY 10011, USA", "1419 Westwood Blvd, Los Angeles | CA 90024-491", "1222 S 27th St, Lincoln, NE 68502, USA" ] for address in addresses: for driver, city in drivers.items(): if city in address: print(f"{address} {driver}") break else: print(f"{address} No Driver Available") This becomes inefficient if you have lots of addresses and lots of drivers. If that is the case you should parse the address to extract the city and have a dictionary of cities (keys) and drivers (values).Both of these fail if you have the same city name used for different cities like Portland Maine and Portland Oregon. |