Skip to content

Adding a search by fips would ideal.  #75

Description

@BudBernhard

Queried CHAT GPT chat.openai, "I have a data set with census fips identifiers, i'd like to find out the zip code of the fips for a python df" and then "instead of printing the zip code append it the row that the fips was in"

from uszipcode import SearchEngine

# Create a search object
search = SearchEngine()

# Assuming your DataFrame is named 'df' and the FIPS identifiers are in a column named 'fips'
df['zip_code'] = None  # Create a new column to store the zip codes

for index, row in df.iterrows():
    fips = row['fips']
    result = search.by_county_fips(fips)

    if result:
        zip_code = result[0].zipcode
        df.at[index, 'zip_code'] = zip_code  # Assign the zip code to the 'zip_code' column in the current row
    else:
        df.at[index, 'zip_code'] = 'Not Found'  # If no zip code is found, assign a placeholder value

# Print the updated DataFrame
print(df)

Nice try AI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions