<jupyter_start><jupyter_text>Adding FIPS (Federal Information Processing Standards) codes to county based on zipcode from data.world<jupyter_code># import modules

import numpy as np
import pandas as pd
# import zipcodes
zipcode = pd.read_csv("data/zipcode_states.csv")
zipcode.head()
zipcode.dtypes
zipcode.shape
# importing FIPS for county; zipcodes
# https://data.world/integrations/python
import datadotworld as dw
results = dw.query(
	'niccolley/us-zipcode-to-county-state', 
    'SELECT * FROM zip_county_fips_2018_03')
results_df = results.dataframe
results_df.head()
# save df to csv
results_df.to_csv("./data/fips.csv")
results_df.shape
results_df.dtypes
results_df.rename(columns={'zip': 'zipcode','stcountyfp': 'fips'}, inplace=True)
results_df.head()
results_df = results_df.apply(pd.to_numeric, errors='ignore')
results_df.dtypes
results_df.head()
# merge FIPS to zipcode df
zipfips = pd.merge(zipcode,results_df[['zipcode','fips']],on='zipcode', how='left')
zipfips.head()
#zipfips['fips'] = zipfips['fips'].apply(lambda x: str(x).zfill(5))
zipfips.dtypes
#zipfips = zipfips['fips'].apply(pd.to_numeric, errors='ignore')
# save df to csv
zipfips.to_csv("./data/zipfips.csv")
count_nan = len(zipfips) - zipfips.count()
count_nan
zipfips.shape
zipfips.tail()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1423076923076923, 'fraction_numerical': 0.005384615384615384, 'mean_word_length': 6.790419161676646, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '244597', 'license': 'MIT', 'n_tokens_mistral': 492, 'n_tokens_neox': 480, 'n_words': 95, 'path': 'zips2fips.ipynb', 'repo_name': 'DistrictDataLabs/city-dash', 'size': '1300'}