I have a dataframe called df1. It includes a zip code column (ie., includes zip codes) and I want to use the pyzipcodes library to create a new column called state, and map the zip codes to states. Does anyone have an idea how to call on and use the pyzipcodes and achieve this task?
I was able to get entries in the state could that look like "ZipCode(zip='85711', city='Tucson', state='AZ'..." but I just want to extract the relevant state with the zip code.
You can use
pandas.Series.mapto map the column of zipcodes with the ZipCode object (that is basically a dictionnary) created bypyzipcode.Output :